Tuesday, 25 August 2015

Gender Validation (Radio Button) using Java Script

HTML File
  
   
  <div class="lbl">Gender : </div>
  <div class="ctrl">
       <input type="radio" name="msex" value="Male" /><span>Male</span>
       <input type="radio" name="fsex" value="Female" /><span>Female</span>
       <span id ="err_gender"></span>
  </div>
  
Java Script File
  
   
function sex_validation(msex, fsex)
{
    count = 0;

    if (msex.checked)
    {
        count++;
    }
    if (fsex.checked)
    {
        count++;
    }
    if (count == 0)
    {
        var msg = "please Select Male/Female";
        document.getElementById("err_gender").innerHTML = msg;
        msex.focus();
        return false;
    }
    else
    {
        alert('Form Succesfully Submitted');
        window.location.reload()
        return true;
    }
}
  

No comments:

Post a Comment