Validating checkbox using javascript

Posted by / 10-Aug-2020 12:20

Dropdown lists usually have one item labelled “Select…”.One way to validate that the user selected something other than the default “Select …” item is to keep its value empty.User-submitted data should also be verified using a secure server-side script.Otherwise a browser with Java Script disabled, or a hacker trying to compromise your site, can easily by-pass client-side validation.The validations also help in lesser server side errors.For example, if you have set length limit in the database for a text input, it is better to do the validation before it actually gets cut off by the database system or even getting an error thrown.Then you can just check for ’emptiness’ : For dropdown lists, we are to set the ‘selected’ attribute for previously selected item.

Let us look at the HTML code showing two check boxes: See the demo The textarea for ‘work permit’ gets disabled if ‘No’ is chosen for ‘Willing to work abroad ?When we display the form back again, it should not loose the form data the user already had filled-in.So we have to display the value from the $_POST in the input value attribute.Client-side form validations help in giving immediate feedback to the user.It is also required to add server side form validation in your form processing script.

validating checkbox using javascript-10validating checkbox using javascript-26validating checkbox using javascript-17

One thought on “validating checkbox using javascript”