473,320 Members | 1,859 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,320 software developers and data experts.

Using variables in [document.VARIABLE.VARIABLE.checked], etc...

I would like to use variables in...

for(q = 0; q < i; q++) {
if(document.varArray1[q].varArray2[q].checked == TRUE) {
alert("YES");
}
else {
alert("NO");
}
}

What's the proper syntax?

--
[ Sugapablo ]
[ http://www.sugapablo.com <--music ]
[ http://www.sugapablo.net <--personal ]
[ su*******@12jabber.com <--jabber IM ]

Jul 23 '05 #1
3 5371
Lee
Sugapablo said:

I would like to use variables in...

for(q = 0; q < i; q++) {
if(document.varArray1[q].varArray2[q].checked == TRUE) {
alert("YES");
}
else {
alert("NO");
}
}

What's the proper syntax?


Assuming that the variables represent the name of a form and
the name of an element in that form, respectively:

if(document.forms[varArray1[q]].elements[varArray2[q]].checked)

Note that there's no need to compare a boolean to true.
Its own value will always be the value of the comparison.

Jul 23 '05 #2
Ivo
"Lee" wrote:
Sugapablo said:

I would like to use variables in...

for(q = 0; q < i; q++) {
if(document.varArray1[q].varArray2[q].checked == TRUE) {
alert("YES");
}
else {
alert("NO");
}
}

What's the proper syntax?


Assuming that the variables represent the name of a form and
the name of an element in that form, respectively:

if(document.forms[varArray1[q]].elements[varArray2[q]].checked)

Note that there's no need to compare a boolean to true.
Its own value will always be the value of the comparison.


This loop will only check the first element in the first form, the second in
the second and the third in the third. If you want to check all items in all
forms, you need to nest two loops.
Also see this naming issue addressed in the FAQ:
<URL: http://jibbering.com/faq/#FAQ4_39 >

HTH
Ivo
Jul 23 '05 #3
JRS: In article <cc*********@drn.newsguy.com>, seen in
news:comp.lang.javascript, Lee <RE**************@cox.net> posted at Thu,
1 Jul 2004 10:50:45 :
Sugapablo said:
if(document.varArray1[q].varArray2[q].checked == TRUE) {

Note that there's no need to compare a boolean to true.
Its own value will always be the value of the comparison.

ISTM that he's not comparing it to true, but to TRUE, which is a
variable, possibly defined. In principle, it could be defined as
TRUE = !!Math.round(Math.random())

It is == true that he should not be using, not == TRUE .

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Jul 23 '05 #4

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

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
1
by: LRW | last post by:
Below is some of the code I'm using. I have a PHP page generating a list of items. I've made it so that each one has a radiobutton with a unique value. You can click on the radiobutton and it will...
15
by: lawrence | last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this script hoping to animate some div blocks on a page. You can see the page here: http://www.keymedia.biz/demo.htm Can anyone...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
8
by: Sergio Otoya | last post by:
Hi all, I need to add an input hidden field to an existing form (post). I have tried a couple things like adding the '<INPUT type=hidden name=idSelectedURL value=http://server/documents>' to...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
7
by: Cordouan | last post by:
I know this looks like it has been answered 1000 times but I have a slightly different problem. I am dealing with forms in order to populate a database. 2 windows : -Main window with my main...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
3
by: Captain Midnight | last post by:
Hi Everyone! This is a great forum by the way.. Anyway, I have a PHP script, that gathers some basic information from a database and pre-populates a form for a user. The HTML that's generated...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.