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
Post a Comment