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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Radio Button Values & Posting to Form Fields

Status
Not open for further replies.

MagnusFox

IS-IT--Management
Jan 12, 2001
51
US
Good day,

I would like to add the values associated with two sets of radio buttons, then post the results in form field text boxes on the same page. I would like the results in each text box to be updated when the user leaves each radio button group (I do not want to have the user click a button to see the results).

Included below is a quick example of the HTML for the radio button groups and text boxes to be populated. The values for the radio button selection are the amount that should show in the text boxes below. The total text box should sum both radio button sections.

In advance, many thanks for your help.

<html>
<body>
<form METHOD=&quot;Post&quot; ACTION=&quot;&quot;>
<b>Section 1</b><br>
<input type=&quot;radio&quot; name=&quot;Section1&quot; value=&quot;2.95-ChoiceA&quot;>Choice A = $2.95<br>
<input type=&quot;radio&quot; name=&quot;Section1&quot; value=&quot;5.95-ChoiceB&quot;>Choice B = $5.95<br>
<input type=&quot;radio&quot; name=&quot;Section1&quot; value=&quot;9.95-ChoiceC&quot;>Choice C = $9.95<br>
<p>
<b>Section 2</b><br>
<input type=&quot;radio&quot; name=&quot;Section2&quot; value=&quot;1.95-ChoiceA&quot;>Choice A = $1.95<br>
<input type=&quot;radio&quot; name=&quot;Section2&quot; value=&quot;3.95-ChoiceB&quot;>Choice B = $3.95<br>
<input type=&quot;radio&quot; name=&quot;Section2&quot; value=&quot;0-ChoiceC&quot;>Choice C = FREE<br>
<p>
Section 1: <input type=&quot;text&quot; name=&quot;Section1Total&quot; size=&quot;20&quot;><br>
Section 2: <input type=&quot;text&quot; name=&quot;Section2Total&quot; size=&quot;20&quot;><br>
TOTAL : <input type=&quot;text&quot; name=&quot;Total&quot; size=&quot;20&quot;>
</form>
</html>
 
<script>
function setPrice(inField){
price = inField.value.substr(0,4)
group = inField.name.substr(7,1)
eval(&quot;document.radioForm.Section&quot; + group + &quot;Total.value = &quot; + price)
price1 = document.radioForm.Section1Total.value
price2 = document.radioForm.Section2Total.value
if (isNaN(price1)){
price1 = 0
}
if (isNaN(price2)){
price2 = 0
}
document.radioForm.Total.value = price1*1 + price2*1
}
</script>
<body>
<form METHOD=&quot;Post&quot; ACTION=&quot;&quot; name=&quot;radioForm&quot;>
<b>Section 1</b><br>
<input type=&quot;radio&quot; name=&quot;Section1&quot; value=&quot;2.95-ChoiceA&quot; onClick=&quot;setPrice(this)&quot;>Choice A = $2.95<br>
<input type=&quot;radio&quot; name=&quot;Section1&quot; value=&quot;5.95-ChoiceB&quot; onClick=&quot;setPrice(this)&quot;>Choice B = $5.95<br>
<input type=&quot;radio&quot; name=&quot;Section1&quot; value=&quot;9.95-ChoiceC&quot; onClick=&quot;setPrice(this)&quot;>Choice C = $9.95<br>
<p>
<b>Section 2</b><br>
<input type=&quot;radio&quot; name=&quot;Section2&quot; value=&quot;1.95-ChoiceA&quot; onClick=&quot;setPrice(this)&quot;>Choice A = $1.95<br>
<input type=&quot;radio&quot; name=&quot;Section2&quot; value=&quot;3.95-ChoiceB&quot; onClick=&quot;setPrice(this)&quot;>Choice B = $3.95<br>
<input type=&quot;radio&quot; name=&quot;Section2&quot; value=&quot;0.00-ChoiceC&quot; onClick=&quot;setPrice(this)&quot;>Choice C = FREE<br>
<p>
Section 1: <input type=&quot;text&quot; name=&quot;Section1Total&quot; size=&quot;20&quot;><br>
Section 2: <input type=&quot;text&quot; name=&quot;Section2Total&quot; size=&quot;20&quot;><br>
TOTAL : <input type=&quot;text&quot; name=&quot;Total&quot; size=&quot;20&quot;>
</form>
</html> Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top