quite new to JQuery and Ive run into a problem. I have a form that is made up of 7 or 8 fieldsets, each with a number of radio buttons. What I need to do is remember each selected option of each radio button in each fieldset as well as changing the stored values if the user decides to change their option. The code I have so far is as follows:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
price = [];
total = 0;
function Update_Subtotal(radio){
$('input:checked').each( function() {
price[1] = radio.getAttribute('price1');
price[2] = radio.getAttribute('price2');
});
$("#1").text("$" + price[1]);
$("#2").text("$" + price[2]);
}
</script>
</head>
<body>
<form name="form" method="post" action="">
<fieldset style="width: 50%;">
<input type="radio" name="opt1" value="1" price1="100" class="1" onclick="Update_Subtotal(this);" />Option 1<br />
<input type="radio" name="opt1" value="2" price1="200" class="1" onclick="Update_Subtotal(this);" />Option 2<br />
<input type="radio" name="opt1" value="3" price1="300" class="1" onclick="Update_Subtotal(this);" />Option 3<br />
</fieldset>
<fieldset style="width: 50%;">
<input type="radio" name="opt2" value="1" price2="10" class="2" onclick="Update_Subtotal(this);" />Option 1<br />
<input type="radio" name="opt2" value="2" price2="20" class="2" onclick="Update_Subtotal(this);" />Option 2<br />
<input type="radio" name="opt2" value="3" price2="30" class="2" onclick="Update_Subtotal(this);" />Option 3<br />
</fieldset>
</form>
Totals:
<div id="1"></div>
<div id="2"></div>
</body>
</html>
This works in so far as to show the changed selection in each fieldset, but when moving to the second fieldset, the total of the first shown in
<div id="1"></div>
becomes
$null
I cannot change the name, value or classes of the input radio buttons either. Any help was be great, thanks!
Without re-writing your HTML, you can try this:
jsFiddle example