?
Solved

Server Side checkbox verification.

Posted on 2003-02-21
4
Medium Priority
?
226 Views
Last Modified: 2007-12-19
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.
0
Comment
Question by:fyc888
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 4

Expert Comment

by:whammy
ID: 7996962
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
 
LVL 15

Expert Comment

by:gladxml
ID: 7997302
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
 

Accepted Solution

by:
ananelson earned 200 total points
ID: 8006926
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
 

Author Comment

by:fyc888
ID: 8013074
Thank you for your help. very much appreciated!

Regards
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question