Validation of radio buttons with Javascript

've combed a ton of the pages on here, and still am incapable to get my explicit validator to work. Basically, when the submit button is clicked, I want the script to verify a radio is checked, if one is checked to do nothing. If one isn't checked I want it to post an alert message.

roughly my html looks like:

my JS page looks like:

function check() {
    var r = document.getElementsByName("c")
    var c = 0

    for(var i=0; i < r.length; i++){
       if(c[i].checked) {
          c = i; }

    alert("please select radio");

asked Jul 21, 2015 in JAVASCRIPT by rajesh
0 votes

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.