Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts

    validate checkbox

    Hi

    Sorry , need a hint on validating checkbox , make sure at least one checkbox is checked.

    Code:
    <form onClick="return formcheck()" name="checkform">
    <input type="checkbox" name="haha[]" value="lala">
    <input type="checkbox" name="haha[]" value="yoyo">
    <input type="submit" name="submit" value="submit">
    </form>
    so what i should write this formcheck function

    Code:
    function formcheck() {
    if (document.checkform.getElements['checkbox'].checked== false){
    alert ('You didn\'t choose any of the checkboxes!');
    return false;
    }else{
    return true;
    }
    }
    is this correct?
    flying dagger

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Sep 2004
    Posts
    713
    Thanks
    6
    Thanked 2 Times in 2 Posts
    thanks
    flying dagger

  • #4
    New to the CF scene
    Join Date
    Mar 2009
    Location
    South Africa
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check Box

    All the examples I have found so far shows something where you have more than one checkbox

    I need a code where the visitor only have to check one box before he can continue, do you perhaps have an example of that?

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    All the examples I have found so far shows something where you have more than one checkbox
    Which means you haven't check the link in my above post.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,922
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by pietpetoors View Post
    All the examples I have found so far shows something where you have more than one checkbox

    I need a code where the visitor only have to check one box before he can continue, do you perhaps have an example of that?
    Do you mean check just one checkbox out of several possible options, or do you mean check a particular single checkbox such as "I agree to the terms and conditions"?

    And what do you mean by "continue"? Enable further input fields? Move to another page? Submit a form?

    Presumably once having checked the box the user may not uncheck it later on? Or if he is able to uncheck it, what happens then?


  •  

    Posting Permissions

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