is there script validation for check box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpchild
Forum Newbie
Posts: 20
Joined: Mon Jul 31, 2006 6:27 am

is there script validation for check box

Post by phpchild »

hi

is there script validation for check box
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post 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.
Post Reply