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

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

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

Post 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
wyred
Forum Commoner
Posts: 86
Joined: Mon Dec 20, 2004 1:59 am
Location: Singapore

Post 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);
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post 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?
wyred
Forum Commoner
Posts: 86
Joined: Mon Dec 20, 2004 1:59 am
Location: Singapore

Post by wyred »

How about posting your html/javascript code so we can take a look?
Post Reply