umair mohsin

umair mohsin

  • 1.4k
  • 387
  • 65.9k

radio button question

Mar 14 2015 5:32 AM

Here is my code which returns value selected by user.

<html>

<head>

<title>my website</title>

<script type="text/javascript">

function myfunction ()

{

var radiobtn = document.form1.rd;

for( var i=0 ; i<radiobtn.length; i++)

{

if(radiobtn[i].checked)

{

alert(" you select " + radiobtn[i].value);

}

}

return true;

}

</script>

</head>

<body>

<form name="form1" method="GET" >

<input type="radio" name="rd" value="male">male

<input type="radio" name="rd" value="female">female

<input type="button" onclick="myfunction()" value="click me">

<input type="reset" value="reset">

</form>

</body>

</html>

I want to generate an alert box if user do not select /forget to select an option from radio buttons using the same coding.can anybody help?


Answers (2)