Validating form input with Java Script is easy to do and can save a lot of unnecessary calls to the server as all processing is handled by the web browser.
It can prevent people from leaving fields blank, from entering too little or too much or from using invalid characters.
The value of a text input box (or a textarea or password input) is available using the syntax that tells you which option has been selected.
The illustration below shows this relationship: Note that the 'I' in selected Index needs to be capitalised - Java Script functions and variables are always case-sensitive. Read more about the humble checkbox in our HTML5 Checkbox Validation article.
When the form is submitted - either by hitting Enter or clicking on the Submit button - the (the 'value' of the field called 'input' belonging to the form). In a real-life situation you will most likely have more fields to check, and more complicated conditions, but the principle remains the same.
In our example, we have a login form with two input fields i.e.
In other words if the first condition fails, the second condition will not be tested and so forth.
Only when all conditions have been satisfied do we reach the command, in which case the form will be submitted.
As usual, I am using Microsoft Ajax to organize my code in namespaces and classes: I will have a static class called “Lists” inside “Shp” namespace and with some help from j Query (I will need it for deferred object) I will add my methods to complete the operations.
My article will show how to sent multiple items to recycle bin using Java Script CSOM.