Radio Object

calendar September 11, 2009

The example demonstrates how to look throught a group of buttons to find out which one is checked and how to use the value attribute.

Note : Members of a group of radio objects must have the same name. Multiple groups can exists within a form but each member of the same group must share the same name.

Code:

<html>
<head>
<title>
Radio Button
</title>

<script type=”text/javascript”>

function myfunction()
{
var myform = document.forms[0];

for(var i=0; i<myform.countries.length; i++)
{
if(myform.countries[i].checked)
break;
}

alert(myform.countries[i].value);
}

</script>

</head>

<body>
<form>
<input type=”radio” name=”countries” value=”Italy” checked />
<input type=”radio” name=”countries” value=”France”  />
<input type=”radio” name=”countries” value=”England” />
<input type=”radio” name=”countries” value=”Spain” />
<input type=”button” value=”Click” onClick=”myfunction();” />
</form>
</body>
</html>

admin

Leave a Reply

You must be logged in to post a comment.