473,320 Members | 1,910 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,320 software developers and data experts.

Possible for javascript to handle 2 values from a radio button?

lee
Hello

I need some javascript code I've written to handle 2 values from an
HTML form.

I've been successful using the "label" attribute (I've simplied the
example below):

<input type="radio" name="group1" value="3" label="Cheese"
checked>Cheese<br>
<input type="radio" name="group1" value="5" label="Meat">Meat<br>
<input type="radio" name="group1" value="15" label="Bread">Bread<br>

But this only works in Internet Explorer, it will not work in
Mozilla/Firebox.

I've also tried id="" but that does not work.

Does anyone know how I can refence 2 values per radio button in
javascript?

Jul 29 '05 #1
3 2758


le*@dnuk.com wrote:

I've been successful using the "label" attribute (I've simplied the
example below):

<input type="radio" name="group1" value="3" label="Cheese"
checked>Cheese<br>
<input type="radio" name="group1" value="5" label="Meat">Meat<br>
<input type="radio" name="group1" value="15" label="Bread">Bread<br>

But this only works in Internet Explorer, it will not work in
Mozilla/Firebox.
I don't see any script in that example so if anything does not work or
does not work as you want it why do you ask in a JavaScript group?

Does anyone know how I can refence 2 values per radio button in
javascript?


I am not sure I understand what you are looking for. Do you want to read
out the value of the label attribute of an element? Then use
element.getAttribute('label')
so assuming you have your radio button group inside of a
<form name="formName">
then you can access the first radio button as
var radioButton = document.forms.formName.elements.group[0];
if (radioButton && radioButton.getAttribute) {
alert(radioButton.getAttribute('label'));
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 29 '05 #2
Lee
le*@dnuk.com said:
Does anyone know how I can refence 2 values per radio button in
javascript?


<html>
<head>
<title>Two Values</title>
<script type="text/javascript">
function showSel(f) {
for (var i=0;i<f.elements.length;i++) {
if(f.elements[i].type=="radio" && f.elements[i].checked) {
var v=f.elements[i].value.split(',');
alert("\""+v[0]+"\" and \""+v[1]+"\"");
}
}
}
</script>
</head>
<body>
<form>
<input type="radio" name="group1" value="3,Cheese" checked>Cheese<br>
<input type="radio" name="group1" value="5,Meat">Meat<br>
<input type="radio" name="group1" value="15,Bread">Bread<br>
<input type="button" value="Show Selection" onclick="showSel(this.form)">
</form>
</body>
</html>

Jul 29 '05 #3
lee
Thanks Lee, that's exactly what I needed.

I've left the script off to keep the question simple.

Thanks.

Jul 29 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Leeor Geva | last post by:
did any of you guys notice when adding an onclick javascript to a Radio Button List, it will get fired BEFORE the Dot is set if you click on the Text for that particular Circle. My onlick calls...
0
by: Ryan Taylor | last post by:
Hello. I am having another issue. I need to execute some JavaScript whenever a radio button is clicked. I am currently using a RadioButtonList control to generate the radio buttons because of...
3
by: Amelyan | last post by:
When we want radio button to belong to a group name we say, radio1.GroupName="GroupA". In this case, radio1 will be unselected if another radio button is selected in "GroupA". Is there a way...
7
by: nathaniel.k.lee | last post by:
Is it not possible, in IE, to dynamically click a radio button? I'm grabbing some values from a database and using them to populate radio buttons on a page. I have alternate code for Firefox...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
1
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
8
by: fanoftvb | last post by:
hi, is it possible to assign values to button? I will not need to enter any values and when i click on the button, the values on the datagrid and database will automatically change. Is there anyway...
7
gskoli
by: gskoli | last post by:
Dear all, Let me tell you the scenario , i have called javascript function on radio button selection , Ex. Suppose There are 3 Radio Button . Let us consider i have clicked on one radio...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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

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.