Server Side checkbox verification.

Hi guys i have a question regarding the above topic.
Well im using vbscript for verification.

supposedly theres a checkbox that follows every record.
if there is only 1 record, there would be no array.
if more than 1, it would be array of same name.

under client side, i tried to check all the box using a button. i manage to check boxes more than 1 checkbox. eg: 2 box.

here is my code :
<script language="vbscript">
sub checkallbox
     dim i
     i = 0
     

     if form.checkbx.length = 0 then
     form.checkbx.checked = false
     
     else
     
     do while i < form.checkbx.length
          form.checkbx(i).checked = true
          i = i + 1
     loop
     end if
end sub
</script>

if theres only 1 reocrd, i click the button, error pops out saying it doesnt support form.checkbx.length since it is not an array.

can anyone help me out with this? either javascript(I'm very noob with it) or vbscript.
fyc888Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ananelsonConnect With a Mentor Commented:
Hi fyc888,

The following VBScript code works for no matter how many checkboxes you have on the page. It relies on the fact that the TypeName() of a collection of checkboxes has the word "Collection" in the name:


<html>
<head>
<script language="vbscript">
    Sub checkallbox
        Dim i

        i = 0
        If InStr(LCase(TypeName(form.checkbx)), "collection") = 0 Then
            form.checkbx.checked = true
        Else
            Do While i < form.checkbx.length
                form.checkbx(i).checked = true
                i = i + 1
            Loop
        End If
    End Sub
</script>
</head>

<body>
<form name="form" id="form">
    <input type="checkbox" name="checkbx">
</form>

<a href="javascript:checkallbox()">Check Everything</a>

</body>
</html>


And here's the same code in Javascript, which is probably the way to go given that only Internet Explorer supports client-side VBScript:


<html>
<head>
<script language="javascript">
    function checkallbox()
    {
        var i;

        i = 0;
        if(!form.checkbx.length)
            form.checkbx.checked = true;
        else
        {
            while(i < form.checkbx.length)
            {
                form.checkbx(i).checked = true;
                i++;
            }
        }
    }
</script>
</head>

<body>
<form name="form" id="form">
    <input type="checkbox" name="checkbx">
</form>

<a href="javascript:checkallbox()">Check Everything</a>

</body>
</html>
0
 
whammyCommented:
You can use:

if (form.checkbx.length) {
 // do something
}

in javascript - I would never use VBScript for anything client-side, since it is only available for use in Internet Explorer browsers.
0
 
gladxmlCommented:
Try to check out the link might help in solving your problem..

The below show how you can manipulate checkbox upon submitting the form... This is using server side...

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20522077.html

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20450556.html


HAppy programming...
0
 
fyc888Author Commented:
Thank you for your help. very much appreciated!

Regards
0
All Courses

From novice to tech pro — start learning today.