Board index » javascript » a way to run through scripts on entire document?

a way to run through scripts on entire document?

2005-04-13 01:25:13 PM
what you see below is the code, which is two parts, a highlight part,
and an unhighlight part. Below that is a sample of its use. What I am
trying to do, is have some sort of javascript, or onload command in the
body tag which will go through all of the 20-30 different <div>tags,
and check the settings of each of those radio boxes. Why? because I am
having the data editable in a form. Is there anyway to have say, a
script click each radio box/input box that has been selected or typed
in?
here is the javascript code...
function highlight(control) {var colour, div;
if(control.value) {colour = '#f3f3f3';}
else {colour = '#ffffff';}
if((div = control.parentNode) && div.style) {
div.style.backgroundColor = colour;
}
}
function unhighlight(control) {var colour, div;
if(control.value) {colour = '#ffffff';}
else {colour = '#f3f3f3';}
if((div = control.parentNode) && div.style) {
div.style.backgroundColor = colour;
}
}
<div class=divn id=dv23>
Do you know javascript?
<input type=radio name=disc value=NULL onclick="unhighlight(this);">
No Answer
<input type=radio name=disc value=0 onclick="highlight(this);">Yes
<input type=radio name=disc value=1 onclick="highlight(this);">No
<br>
Details: <br><textarea name=discd cols=60 rows=3></textarea>
</div>
-
 

Re:a way to run through scripts on entire document?

grandeandy@gmail.com wrote:
Quote
what you see below is the code, which is two parts, a highlight part,
and an unhighlight part. Below that is a sample of its use. What I am
trying to do, is have some sort of javascript, or onload command in the
body tag which will go through all of the 20-30 different <div>tags,
and check the settings of each of those radio boxes.
var allTheDivs = document.getElementsByTagName('div');
var currentDiv;
var i = allTheDivs.length;
while (i--) {
currentDiv = allTheDivs[i];
// do something to the current div
}
Quote
Why? because I am
having the data editable in a form. Is there anyway to have say, a
script click each radio box/input box that has been selected or typed
in?

Inside the above while loop after assigning a value to currentDiv:
var ele;
var inputs = currentDiv.getElementsByTagName('input');
var j = inputs.length;
while ( j-- ) {
ele = inputs[j];
if ( /text/i.test(ele.type) ) {
// do text input stuff with ele
} else if ( /radio/i.test(ele.type) ) {
// do radio button collection stuff with ele
}
}
Quote
here is the javascript code...

[...]
--
Rob
-