Php code for validating the form

We know that the checkbox is unchecked by default so we need to tell the browser what message to display.

The event handler on the checkbox then toggles the error message.

This is also possible with text will now toggle the checkbox state, and the text will change from red to green.

Basically, when the checkbox is happy, the label is happy.

The attribute on checkboxes is supported in Internet Explorer 10 and most/all other browsers exept for Safari which ignores the requirement.

Some, but not all, browsers will recognise and enforce this: The advantage of the HTML5 form validation is that it happens before our Java Script is called, displays instructions and points the user to the relevant element.At time of writing Safari does not enforce input fields.If you're using Safari or another unsupporting browsers all the examples will just display the Java Script alert box.Here you can see screen captures from Firefox and Chrome: Text alert messages are generated entirely by the browser and will even translate automatically into different languages - something that would be almost impossible using just Java Script.The advantage for the user is that it's obvious whick element is causing the problem and there's no alert window that needs to be clicked away.

Leave a Reply