SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: check box array

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Pakistan
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    check box array

    there is a problem with me...can any body help me??
    the problem is that i have 108 check boxex on my form...
    name of each check box is "names[]" so iut means its an array of check boxes...now before submit i have to check that atleast one check box must be checked...so kindly tell me how will i check in the java script function that at least one check box must be check else i have to show an alert
    regards

  2. #2
    SitePoint Enthusiast RaS!'s Avatar
    Join Date
    Mar 2004
    Location
    Italy
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My solution

    Quote Originally Posted by salmanucit
    there is a problem with me...can any body help me??
    the problem is that i have 108 check boxex on my form...
    name of each check box is "names[]" so iut means its an array of check boxes...now before submit i have to check that atleast one check box must be checked...so kindly tell me how will i check in the java script function that at least one check box must be check else i have to show an alert
    regards
    I had the same problem. The name of my checkbox wasn't an array-like, so I could wrote a js function that check if at least one of them is checked:

    Code:
    function CheckAll(form) {
     var counter=0;
     for (k=0;k<num_of_checkbox;k++) {
      if (eval("form.mycheckbox("+k+").checked==true))
       counter++
     }
     if (counter==0)
      alert("You must select a checkbox!");
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •