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.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.
That could be done using Ajax, but would make the CAPTCHA much easier to break.I've coded a working form, all checks are great but for some reason the hardest part is trying to stop form submission before validation.So i have places to insert the stop validation code, but just cant find any that works.Even if users correctly enter an integer, for example, you might need to make sure that the value falls within a certain range.Note Important Validating user input is also important for security.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.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.Normally you would modify this so that you could submit or not submit the form based on the number of items selected. For example, a text input that only needs to have a value if a checkbox is checked: Using simple logical operators and the functions supplied above you can do all sorts of client-side form validation.To take things a step further you can even explore Ajax Form Validation which lets you supply real-time feedback using server-side scripts triggered by Java Script events.