
How to: Loop through all objects and count the checked check boxes
Thanks Michael!
But still no luck :-(
Here's all the code:
'##############################################################
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<Form Name=Form>
<INPUT type="checkbox" id=checkbox1 name=checkbox1 checked><BR>
<INPUT type="checkbox" id=checkbox2 name=checkbox1><BR>
<INPUT type="checkbox" id=checkbox3 name=checkbox1><BR>
<INPUT type="checkbox" id=checkbox4 name=checkbox1><BR>
<INPUT type="checkbox" id=checkbox5 name=checkbox1><BR>
<INPUT type="checkbox" id=checkbox6 name=checkbox1><BR>
<INPUT type="checkbox" id=checkbox7 name=checkbox1><BR>
<INPUT type="checkbox" id=checkbox8 name=checkbox1><BR>
<INPUT type="checkbox" id=checkbox9 name=checkbox1><BR>
<INPUT type="checkbox" id=checkbox10 name=checkbox1><BR>
<INPUT type="button" value="Button" id=button1 name=button1
Language=VbScript onclick="CountChecked()">
<Script Language=VbScript>
sub CountChecked()
for i = 1 to document.all.length
set objChk = document.all("checkbox" & i)
if objChk.Checked = True then
buffer = buffer + 1
end if
next
MsgBox "Whats up? " & buffer
end sub
</Script>
</Form>
</BODY>
</HTML>
'##############################################################
Figured maybe someone want's to try this
and see if he/she can get it to work...
btw I can get all this to work in javascript, no
problem! One of my students is just starting of
with asp and vbscript so I figured: let him start
with "simple" client side vbscript :-(
Marc (Amsterdam, The Netherlands)
Quote:
>Just as a test, try
>MsgBox "ABC" + buffer + "XYZ"
>instead of
>MsgBox buffer
>to see what you get.
>In the code shown, the variable buffer isn't initialized: try
>initializing it. As I recall, a null variable will suppress MsgBox
>output. The "+" operation in JavaScript does both
>a) addition of numeric values and
>b) concatenation of strings.
>So if the code is treating buffer as a string, you will have problems.
>> I know... :-)
>> sub CountChecked()
>> for i = 1 to document.all.length
>> set objChk = document.all("checkbox" & i)
>> if objChk.Checked = True then
>> buffer = buffer + 1
>> end if
>> next
>> MsgBox buffer
>> end sub
>> it still won't trigger the messagebox :-(
>> Marc (Amsterdam, The Netherlands)
>> >The VBScript version of Alert is MsgBox
>> >MsgBox buffer