2
Answers

radio button question

Ask a question

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)