Validating multiple checkboxes using javascript

It is checking that at least one checkbox is checked.

I only don't like that I have to manually call validate for one Checked-Validator on form submission.

We use return false; because when this function is called when the form is submitted and if this textbox is found empty the page shouldn’t be submitted so returning the boolean value false with prevent the form from being submitted.

An HTML combobox shows a dropdown list of items from which one item is selected.

This is similar to radiobutton example explained above.This is a bit tricky first we need to check if none of the radiobuttons are checked then display a message.For this we use a variable which is incremented each time a radiobutton is NOT checked then it is compared with the number of radiobuttons in that group, if both are equal a message is displayed.We need to check if it is equal to null or “” because different browsers act differently so its better to check for both the conditions.The following function checks whether the texbox with id name1 is empty, if empty it displays a message and highlights that textbox with red color.You can set the value to be a ‘1’ or ‘on’ instead of ‘Yes’.


Leave a Reply