|
-
November 14th, 2002, 11:56 PM
#1
multiple checkbox question
hey there...
i'm using IE 6...and i've got this javascript code:
var totalCheck = theForm.chkDelete.length;
alert(theForm.chkDelete.value);
alert(theForm.chkDelete.length);
okay...now i have this html on the page:
<input type="checkbox" name="chkDelete" value="#EventID#">
instead a cfoutput loop...so in a loop.
now when i have 2 or more checkboxes on the page it works fine...i get
chkDelete.value = (whatever the first EventID is)
chkDelete.length = 2
but when i have only one checkbox the .value works the same...but the length is undefined.
what's going on here and how can i test for just one box if it won't work this way?
thanks!
b
-
November 18th, 2002, 02:27 PM
#2
I'm assuming all of your checkboxes have the same name??
If so, they are referred to as indices in an array - chkDelete[0], chkDelete[1], etc.
The length property defines how many members are in the array.
When there is only one checkbox, the length is undefined because there have to be at least 2 members in any array in JavaScript.
For the special case of one checkbox, simply do:
if (theForm.chkDelete.length) {
// code for 2 or more checkboxes
for (i=0; i< theForm.chkDelete.length; i++) {
foo = theForm.chkDelete[i].value;
alert(foo);
}
} else {
// code for 1 checkbox
foo = theForm.chkDelete.value;
alert(foo);
}
-
November 18th, 2002, 03:28 PM
#3
this is what i was thinking you'd say...i just couldn't find any documentation on it for sure. sounds like a good fix.
i should've know the websmith would know...again. thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|