Page 1 of 1

find out if a control is part of an array - javascript

Posted: Fri Jun 03, 2005 1:23 am
by Stryks
Hi all, just a quick problem I am trying to solve, I have a few checkboxes in a form and when a user ticks on, it loops through, checks the checked status and performs an action according to that.

That works fine if there are multiple checkboxes, but in the instance of there only being one, it comes to the loop ...

Code: Select all

for (var i=0; i<control.form.add_ing.length; i++){
... it just passes over without doing anything.

How can I tell if there is only one?

Cheers

Posted: Fri Jun 03, 2005 2:42 am
by wyred
Might want to check what's the value of 'control.form.add_ing.length' when there's only 1 checkbox.

Code: Select all

alert(control.form.add_ing.length);

Posted: Fri Jun 03, 2005 7:54 am
by Stryks
I wasnt really sure how to about that, so I just did an alert() and it showed up undefined. After a bit of testing, I found that this worked.

Code: Select all

if (isNaN(control.form.add_ing.length)) do stuff
It's probrably not the right way to go about it though. Any problems with this method?

Posted: Sun Jun 05, 2005 9:01 pm
by wyred
How about posting your html/javascript code so we can take a look?