javascript - How do I validate my Radio Buttons -


i've started programming , i'm @ basic level, i've created form student website , i'm trying validate radio buttons. know can select "checked" in html code tutor stipulates has within javascript code. have researched on here examples many of have shown haven't worked me (my fault!) , crashes previous validations.

any guidance ninjas appreciated. here small sample of code work me have deleted radio button validation in frustration, want know how adapt code:

<script>       function validate(){     firstname = document.getelementbyid("txtfirst").value;      errors = "";      if (firstname == ""){       errors += "please supply valid first name \n";     } else if (!firstname.match(/^[a-za-z-\s]*$/)){       errors += "please use letters in first name \n";     }   } </script>   <body> <form method="post" action="" class="booking"> <fieldset>   <div>     <label for="txtfirst" class="fixedwidth">first name</label>     <input type="text" name="txtfirst" id="txtfirst"/>   </div>    <div class="buttonarea">     <input type="submit" value="submit" onclick="validate()"/>   </div> </fieldset> </form> 

i recommend jquery need check $('element').val(). in javascript have check document.getelementbyid('element').value. remember match both name , id properties work can select 1 value in set of radioboxes.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -