Forum Moderators: open

Message Too Old, No Replies

JavaScript Loop Identifiers

there must be a way

         

Sangarius

9:27 pm on May 17, 2004 (gmt 0)

10+ Year Member



Hello,

I am having a syntax problem with Javascript that I'm sure is not my logic.

Ok, I have several html drop down boxes each named Active<%=count%> so the html reads Active1, Active2, Active3 and so on. Each of these drop down boxes has a value of true or false. When the submit button is pressed, I pass in the value of count to a JavaScript function, which goes in correctly. There can only be one true value out of all the drop down boxes. My problem is when I try to check for more than one true value by concatenating a string like so :
if(thisfrm.Active + count.value=="False") {
tripswitch ++;
}
tripswitch is equal to 0, which means it's not being read and if I change ".Active + count" to ".Active1" tripswitch is equal to 2 which is correct. Because the value of count is determined by an unknown amount of recordsets, is there anyway to anchor the count variable onto the field name? Any help is much appreciated.

Thank You,
Sangarius

Sangarius

9:42 pm on May 17, 2004 (gmt 0)

10+ Year Member



way hey! Just figured it out, I have to reference it like an object

if(thisfrm.elements('NotActive' + count).value=="False") {

Now it knows what element I mean.

Bernard Marx

9:47 pm on May 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, I'm trying to fully understand the problem, so there may be more.
So far, I understand that your field names are Active1, Active2 etc.

1. I'd recommend sticking to lower case to avoid problems...anyway
2. You won't be able to concatenate a reference like that:

thisfrm.Active + count.value XXX

but like this

thisfrm.["Active" + count].value

does this help?

------ after ---------------

..or indeed like that!