Validating Checkbox

Discussions

Web tier: servlets, JSP, Web frameworks: Validating Checkbox

  1. Validating Checkbox (2 messages)

    Hi,

    I am creating a table in JSP which contains records which are dynamically displayed and which also contains Checkbox.

    I am updating the database depending upon the selection of the checkboxes.

    The functionality is working fine but I am unable to throw a validation message in case the user does not select any of the checkboxes.

    I have used Javascript for that but thats not working.

    Here is the piece of javascript
    <html>
    <head></head>
    <Script language="javascript">
    function validatefunc()
    {
    if(document.myForm.check.checked=false)
    {
    alert("please select checkbox");
    }

    }


    </script>
    <body>
    <form name=myForm action=Acc.jsp>

    <input type =checkbox name=check>
    <input type =submit name=submit onSubmit= onSubmit="javascript:validatefunc();return false;">
    </form>
    </body>
    </html>




    Threaded Messages (2)

  2. Validating Checkbox[ Go to top ]

    try this

    if(document.myForm.elements[val].checked==true)

    and.......


    <input type =checkbox name=check id=val>

    now if u have multiple checkboxes u need to generate ids as
    val1, val2, val3 ....

    so also u have to write a loop around the if(to check for val1,val2,val3...). then if condition is not satisfied keep a flag. and check the flag after the loop and display the error.

    hope this helps.


  3. Validating Checkbox[ Go to top ]

    Hi,

    I think ur code is right, but u have used single = (ASSIGNMENT) instead of == (EQUALITY) that might be the problrm..