Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hidden field and radio button 1

Status
Not open for further replies.

nm61

Programmer
Joined
May 25, 2004
Messages
14
Location
CA
Hello
Is it possible to add a hidden field to a radio button? I have a series of radio buttons grouped in four groups. When the form is submitted I get an email with the value of each button listed. I would like to get in addition to the value the name of the selected radio button. I hope this is clear enough. Thanks
 
Here's an example of how to access the value of the radio button, as well as the name:
Code:
<script language=JavaScript>

function alertValues(obj) {
   str = "";
   str += "Radio Name: " + obj.name + "\n";
   str += "Radio Value: " + obj.value;
   alert(str);
}

</script>
<body>
<form name=blahForm>
<input type=radio name=myRadio value=blah onclick='alertValues(this)'>Click the button
</form>
</body>

-kaht

banghead.gif
 
Hello kaht
I am sorry but I probably was not very clear. The form I have has four groups of radio buttons. When I email it I get the value of the selected button and the name of the group that the selected button belongs to. I am trying to add a field that would also include the name of the selected button as well as the value and the name of the group when the form is emailed.

This is the code for one button.

<td width="10" valign="top"><input type=radio name=group1 onClick='calculateTotals(this.name, this.value)' value=10></td>
<td width="200" valign="top">Button1</td>

This is the email I get

group1=10
group2=14
group3=42
group4=13


This is what I am trying to get

group1=10 Button1
group2=14 Button3
group3=42 Button4
group4=13 Button1

Thank you.
 
Ok, here's a modified script to get the values you're looking for. I don't think radio groups have an inherent way to find out which one in the array was clicked, so you'll have to loop thru to find the selected button:
Code:
<script language=JavaScript>

function alertValues(obj) {
   str = "";
   str += "Radio Group: " + obj.name + "\n";
   str += "Radio Value: " + obj.value + "\n";
   radioGroup = document.blahForm.elements[obj.name];
   for (i = 0; i < radioGroup.length; i++) {
      if (radioGroup[i].checked) {
         str += "Radio Button: " + i;
      }
   }
   alert(str);
}

</script>
<body>
<form name=blahForm>
Click a button<br>
<input type=radio name=myRadio value=blah1 onclick='alertValues(this)'><br>
<input type=radio name=myRadio value=blah2 onclick='alertValues(this)'><br>
<input type=radio name=myRadio value=blah3 onclick='alertValues(this)'><br>
<input type=radio name=myRadio value=blah4 onclick='alertValues(this)'><br>
</form>
</body>

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top