473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

a way to run through scripts on entire document?

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>

Jul 23 '05 #1
1 1286
gr********@gmail.com wrote:
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
}
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...

[...]
--
Rob
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: JR | last post by:
Hi. I have a CGI script that will need to call itself an unknown number of times, to add rows, run queries, etc. At the bottom of the output that is produced by the script, there are four...
12
by: Mary Catherine | last post by:
I have 2 scipts that I am trying to get to run on the same page. One is a time/date script, the other is a countdown script (i.e. countdown days, hours, mins until a given date). They both work...
3
by: P Wolpert | last post by:
This is my first post. I hope I don't sound stupid. I have a script conflict when I put two scripts on one page. Both scripts will work if I use one at a time but the menu button script will not...
2
by: petermichaux | last post by:
Hi, My AJAX response is a bit of HTML that I insert into the DOM. I extract the contents of the script elements in the response into an array called aScripts. I then want to append these to an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.