Page 1 of 1

is there script validation for check box

Posted: Fri Aug 11, 2006 8:18 am
by phpchild
hi

is there script validation for check box

Posted: Fri Aug 11, 2006 8:35 am
by Grim...
You mean, to make sure it's checked?

Javascript would be something like this:

Code: Select all

<script type="text/javascript">
function validate()
{
    x = document.formname.getelementbyid(my_box).value;
    if (x == 1)
    {
        document.formname.submit();
    }
    else
    {
        alert('Check the box!');
    }
}

</script>
<form name="formname" action="submit.htm">
<input type="checkbox" id="my_box" name="box" value=1 />
<input type="button" value="submit" onclick="validate()" />
</form>
Not checked, but it should be fine.