By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,036 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,036 IT Pros & Developers. It's quick & easy.

value of radio button...

P: n/a
Is there an easier way to do this (what I am trying to do, is have 3 radio
buttons and when the submit button is clicked, easily determine which radio
button was selcted). NOTE: the radio buttons are in 3 different cells of a
table, so I can't use the <select></select> tags....
HTML:
<form name="SelectOrder">
<tr><tr><input type="radio" name="OrderType" value="C">'C' Orders<br
/></input></td></tr>
<tr><tr><input type="radio" name="OrderType" value="A">'A' Orders<br
/></input></td></tr>
<tr><tr><input type="radio" name="OrderType" value="B" checked>Both Order
Types<br /></input></td></tr>
<tr><tr><input type="button" name="btn1" value="Submit"
onClick="Submit_Form(document.forms[1])"></input></td></tr>
</form>

<script language="javascript>
function Submit_Form(frm) {
if (document.SelectOrder.OrderType[0].checked==true){
alert('C');
} else {
if (document.SelectOrder.OrderType[1].checked==true){
alert('A');
} else {
alert('B');
}
}
}
</script>
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ruskin wrote:
Is there an easier way to do this (what I am trying to do, is have 3 radio
buttons and when the submit button is clicked, easily determine which
radio button was selcted). NOTE: the radio buttons are in 3 different
cells of a table, so I can't use the <select></select> tags....
HTML:
<form name="SelectOrder">
<tr><tr><input type="radio" name="OrderType" value="C">'C' Orders<br
/></input></td></tr>
<tr><tr><input type="radio" name="OrderType" value="A">'A' Orders<br
/></input></td></tr>
<tr><tr><input type="radio" name="OrderType" value="B" checked>Both Order
Types<br /></input></td></tr>
<tr><tr><input type="button" name="btn1" value="Submit"
onClick="Submit_Form(document.forms[1])"></input></td></tr>
</form>

<script language="javascript>
function Submit_Form(frm) {
if (document.SelectOrder.OrderType[0].checked==true){
alert('C');
} else {
if (document.SelectOrder.OrderType[1].checked==true){
alert('A');
} else {
alert('B');
}
}
}
</script>


Hi Ruskin,

1) use length on the radiobutton-object.
2) loop and check.

something like this:
I didn't check it, so forgive typos and blunders. :-)

<script type="text/javascript>
function Submit_Form(frm) {
numberOfButtons = document.forms.SelectOrder.OrderType.length;
for (i=0;i<numberOfButtons;i++) {
if (document.forms.SelectOrder.OrderType[i].checked){
theVal = document.forms.SelectOrder.OrderType[i].value;
alert(theVal);
}
}
</script>
PS: Use selectedIndex if you use Select/option elements.

Regards,
Erwin Moller
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.