Validating form elements
We do this with the following: Next we will validate that a Latitude coordinate was entered in the form, is a proper number, and is in the valid range of -90 to 90.
If not, we generate error messages and set the sentinel var to FALSE.
Note that the button type is SUBMIT, that means when the button is clicked, the form will be submitted, and will be submitted regardless of any JQuery code that is run. However, we need to change this so that the form does not do a default SUBMIT when clicked.
We do this by changing the button TYPE from SUBMIT, to BUTTON, like in the following: Now, after this change, the form will only be submitted after we tell the JQuery code to do the submit, and that will only happen after the JQuery validates the data inputted into the form as being correct data. NET MVC Web Application, we will have to create a SCRIPTS section at the bottom of the Locations view and include a JQuery opening statement like the following: Now, this code will run specific JQuery code when the Find BTN button is clicked, after the button is clicked, we want to check the data in the form elements of the form to make sure that is correct data.
First we will add the following code to setup our validation section, a statement to clear out any previous error messages, and including a boolean variable to be a sentinel whether the form will be submitted or not, and also simple vars for the form elements themselves.
The word ERROR represents a CSS class we are going to use in our generated error messages.
If errors were encountered, error messages will be shown on the web page and the sentinel var will be FALSE.