Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

which radio is checked? 2

Status
Not open for further replies.

y2k1981

Programmer
Aug 2, 2002
773
IE
How can I code to check with radio button is checked? If no radio is checked, i want to do A, if radio1 is checked, do B and if Radio2 is checked, do C. but how do I find out which radio button is checked?
Code:
<form name=&quot;form1&quot;>
<input type=&quot;radio&quot; name=&quot;selection&quot; value=&quot;radio1&quot;>
<input type=&quot;radio&quot; name=&quot;selection&quot; value=&quot;radio2&quot;>

I've tried using if(document.form1.selection.checked.value == &quot;radio1&quot; but that doesn't work

plz, any ideas?
 
Try (document.form1.selection[0].checked == true) for radio1 ---------------------------------------
[turkey] HAPPY THANKSGIVING!!!! [turkey]
mikewolf@tst-us.com
 
nop, didn't work!! said True is undefined
 
<script>
function checkRadio(){
alert(document.form1.selection[0].checked)
}

</script>
<form name=&quot;form1&quot;>
<input type=&quot;radio&quot; name=&quot;selection&quot; value=&quot;radio1&quot; onClick=&quot;checkRadio()&quot;>
<input type=&quot;radio&quot; name=&quot;selection&quot; value=&quot;radio2&quot; onClick=&quot;checkRadio()&quot;>
</form>

This script runs in IE 5.5.... ---------------------------------------
[turkey] HAPPY THANKSGIVING!!!! [turkey]
mikewolf@tst-us.com
 
Search the FAQs before asking on the forums. There one that talks exactly about what you want : faq216-342 Water is not bad as long as it stays out human body ;-)
 
I did go through the faq's, I don't know how I missed that one though!!

Well, thank you both for your help
 
y2k1981,

Here is how I do it:

var response=0;
for (var i=1; i <= form1.selection.length; i++) {
if (form1.selection[i-1].checked) {
var response = i;
break;
}
}

If response == 0, then nothing was selected; otherwise, response holds the sequential number (not index) of the button selected.

Good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top