You could store the dollar values in an object instead.
var costs = {
"paper" : 0,
"usb" : 0,
"both" : 0
};
The values of the radio buttons can (and should) be unique.
<input type="radio" value="paper" name="Syllabus" checked="No" /> Paper ($0)<br />
<input type="radio" value="usb" name="Syllabus" checked="No" /> USB ($0)<br />
<input type="radio" value="both" name="Syllabus" checked="No" /> Both ($20)<br />
And then, in your CalculateTotal function, reference costs["paper"]
, etc.
manpreet
Best Answer
2 years ago
So I'm working on an order form, where people can select different quantities of items, and it then uses">uses JS to calculate to the totals. So for example you can select 2 Brown hats ($15 each) and the TOTAL automatically becomes $30. In the POST page I can then pull the name of the text box and know they ordered 2 brown hats.
Here is my problem: I want to set up a radio button option that will allow them to select one item only, and have it add to that final total here is what it looks like:
So how can I use JS to add $20 to the total if "BOTH" is selected? And then of course $20 is removed if they select one of the other options. And finally, if they do select PAPER or USB, how do I know in the final output what they selected, since the value will be 0 either way?
Thanks for the help!
------ IF IT HELPS ANYONE HERE IS THE CODE I USE TO ADD THE VALUES OF THE OTHER TEXT BOXES, I THEN PAD THE TOTAL WITH ZEROS AND ROUND IT ------