Click to See Complete Forum and Search --> : Detecting which radio button is checked


Arc
09-06-2003, 01:53 PM
Hello,
I have two radio buttons both named "radMode". So it's an array.

<input type="radio" name="radMode" id="NewsBrief" value="NewsBrief">
<input type="radio" name="radMode" id="FullArticle" value="FullArticle" checked>


One has checked value of "NewsBrief" the other has a checked value of "FullArticle".

I have tried everything I can think of to determine which one of these is checked.

Some examples would be

if(document.form.radMode[1].checked == true)
if(document.form.radMode[1].value == "FullArticle")
if(document.form.radMode.checked.value == "FullArticle")


etc...

So how do I know which one is currently checked?


Thanks!:D

Khalid Ali
09-06-2003, 02:04 PM
Here is a working example

script type="text/javascript">
<!--
function Process(){
var frm = document.getElementById("form1").rd;
for(var n=0;n<frm.length;n++){
if(frm[n].checked==true){
alert(frm[n].value)
}
}
}
//-->
</script>
</head>
<body class="body">
<form id="form1" action="" onsubmit="">
<input type="radio" name="rd" value="newsBrief"/><br/>
<input type="radio" name="rd" value="fullArticlef"/>
<input type="button" value="process" onclick="Process()"/>