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.
In the case of a checkbox multiple values can be selected so validation is done if none of the checkboxes are ticked.
You can also validate by requiring the user to select a minimum of one value or two value according to your requirement.
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.