For an alternative approach to client-side form validation, without Java Script, check out our new article on HTML5 Form Validation which is available now in most modern browsers.When form input is important, it should always be verified using a secure server-side script.The team at have made a video based on this article as a part of their Java Script training lessons which you can view below.It explains some of the code examples above as well as introducing more advanced concepts: Very new to coding. Would be great if you could post full examples of code including form and not just pieces that fit into the greater framework of code.Here, we are giving our Java Script codes for validating Login form.In our example, we have a login form with two input fields i.e.
Other form values are available using a similar syntax, although this becomes more complicated if you're using SELECT lists, checkboxes or radio buttons (see below for examples). All you need to do is extend the command is encountered, execution of the function is halted.
Radio buttons are implemented as if they were an array of checkboxes.
To find out which value (if any) has been selected, you need to loop through the array until you find which one has been selected: In the case of a single radio button we have nothing to loop through so just return either it's value, if the radio button is checked, or false.
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.