a way to run through scripts on entire document?

G

grandeandy

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>
 
R

RobG

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;
// do something to the current div
}
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
}
}
here is the javascript code...
[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top