value of radio button...

R

Ruskin

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>
 
E

Erwin Moller

Ruskin said:
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.checked){
theVal = document.forms.SelectOrder.OrderType.value;
alert(theVal);
}
}
</script>


PS: Use selectedIndex if you use Select/option elements.

Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top