473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

value of radio button...

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
1 1487
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Randell D. | last post by:
Folks, I have a form (called FORM1) - In my INPUT submit tag, I have an onClick event that I have successfully tested/used to display the value of a TEXT box using the following function (called...
2
by: jason | last post by:
The following (likely far from imperfect code), reports a value of NaN in the j4 display. I suppose the problem is I am not really passing the "checked" value of the radio button via .value ......
4
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
2
by: Stoic | last post by:
I'm offering a selection of three items. One is $25, the second is $50, the third is $100. Along with selection one of the items I need to pass the quantity of the selection. Here is the code now....
2
by: darrel | last post by:
I'm using some standard HTML radio buttons (to allow finer javascript interaction) on a web page and would like to catch the selected item on postback. Since they are all ID's uniquely, is there a...
2
by: Mirovk | last post by:
Hi, I have a session variable wich value arrives from a previous .asp but in my actual page I need to modify it based upon a selected value from a radio button. I will try to figure out for...
3
by: romano2717 | last post by:
I have a test.php file that contains a set of radio buttons generated inside a loop. then I append the $i variable to the radio button name to have a unique set of radio buttons. the scenario...
1
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
5
by: mad.scientist.jr | last post by:
According to http://www.quirksmode.org/js/forms.html you need to look through a radio button's members to find the value: I tried writing a reusable function to return the value, see code at:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.