Validating checkboxes in java script

For example, you may want to ensure that someone inserts a valid e-mail address into a text box, or perhaps you want to ensure that someone fills in certain fields.

Microsoft® Office Front Page® 2003 allows you to create some custom validation within the form feature.

(For more information on how to create form validation using the Front Page form feature, see About creating forms in Front Page 2003.) However, if the form validation provided in Front Page does not suit your needs or the site on which you are working is hosted on a server that does not have Front Page Server Extensions from Microsoft installed, you may need to create custom form validation.

validating checkboxes in java script-68validating checkboxes in java script-68validating checkboxes in java script-88

However, for some form functions, server-side validation is necessary.

For example, if you have a form that populates a drop-down list based on the value of another form field, server-side processing may be needed to pull data from a database and populate the drop-down list.

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.

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.

Client-side validation provides validation within the browser on client computers through Java Script.

Because the code is stored within the page or within a linked file, it is downloaded into the browser when a user accesses the page and, therefore, doesn't require a roundtrip to the server.If a textbox is empty or an option is not selected we can use javascript to display an alert message, and highlight the empty field and also we should make sure the page stays the same and doesn’t get “submitted” Javascript validation is a client side validation and relies on the web browser so it should not be solely relied upon Textbox is the simplest element to validate if empty or not.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.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.In the case of a checkbox multiple values can be selected so validation is done if none of the checkboxes are ticked.For this reason, client form validation can be faster than server-side validation.

Tags: , ,