473,776 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="SelectOrd er">
<tr><tr><inpu t type="radio" name="OrderType " value="C">'C' Orders<br
/></input></td></tr>
<tr><tr><inpu t type="radio" name="OrderType " value="A">'A' Orders<br
/></input></td></tr>
<tr><tr><inpu t type="radio" name="OrderType " value="B" checked>Both Order
Types<br /></input></td></tr>
<tr><tr><inpu t type="button" name="btn1" value="Submit"
onClick="Submit _Form(document. forms[1])"></input></td></tr>
</form>

<script language="javas cript>
function Submit_Form(frm ) {
if (document.Selec tOrder.OrderTyp e[0].checked==true) {
alert('C');
} else {
if (document.Selec tOrder.OrderTyp e[1].checked==true) {
alert('A');
} else {
alert('B');
}
}
}
</script>
Jul 23 '05 #1
1 1508
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="SelectOrd er">
<tr><tr><inpu t type="radio" name="OrderType " value="C">'C' Orders<br
/></input></td></tr>
<tr><tr><inpu t type="radio" name="OrderType " value="A">'A' Orders<br
/></input></td></tr>
<tr><tr><inpu t type="radio" name="OrderType " value="B" checked>Both Order
Types<br /></input></td></tr>
<tr><tr><inpu t type="button" name="btn1" value="Submit"
onClick="Submit _Form(document. forms[1])"></input></td></tr>
</form>

<script language="javas cript>
function Submit_Form(frm ) {
if (document.Selec tOrder.OrderTyp e[0].checked==true) {
alert('C');
} else {
if (document.Selec tOrder.OrderTyp e[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.Ord erType.length;
for (i=0;i<numberOf Buttons;i++) {
if (document.forms .SelectOrder.Or derType[i].checked){
theVal = document.forms. SelectOrder.Ord erType[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
24441
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 via an onClick event) <script type="text/javascript"> function performPrePostChecks() { // myName being an iput text box
2
12349
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 ... without having to get this value via html, is there any way I can passed the checked value via html .. maybe with syntax like n4.checked.value or something.. Many thanks. <html>
4
4135
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 the NO radio button, once I do that it will not work. Any help would be greatly appreciated. Mitch
1
3436
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 ***********************, I've included all the code incase that isn't where the problem is. Any help would be hugely appreciated. Mick
2
2894
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. <tr><td><input type="radio" name="item_name" value="Reduced">Reduced</td><td><input type="radio" name="amount" value="25">$25.00ea.</td></tr> <tr><td><input type="radio" name="item_name" value="Regular">Regular</td><td><input type="radio"...
2
1549
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 way to grab only the selected item's value? Or do I need to write an if/then statement to figure out which one is selected? Sample: <input runat="server" id="radio1" name="category" /> <input runat="server" id="radio2" name="category" />
2
3404
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 better understanding: page1.asp ---session("PaymentMethod") page2.asp ---Depending on the radio button selected the payment
3
2864
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 should be this: when i click the submit button, test2.php should display the values of the radio buttons selected in the test.php file FILE: test.php <html> <head> <title>RADIO</title> </head> <body>
1
4085
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 hotspots on the image. One being correct(a) and the other incorrect(b). When the user clicks on the correct hotspot or place on the image, it should score and retain that value until the end of the quiz. At the end of the quiz, there is a submit button...
5
3601
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: http://www.geocities.com/usenet_daughter/javascript_radio.htm but for some reason I can only get a value if I hard code the control name.
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.