I have a price list and would like to display in a table a summary of the choices made by the user with its total price.
To do this I tried to do it this way
HTML
<div>
<p>PICK ONE</p>
<input type="radio" name="weight" value="range-1" checked><label>0-10 ($ 10)</label>
<input type="radio" name="weight" value="range-2"><label>10-20 ($ 20)</label>
<input type="radio" name="weight" value="range-3"><label>20-30 ($ 30)</label>
</div>
<div>
<p>ADD EXTRA</p>
<input type="checkbox" id="urgentchk" name="urgentchk" value="1" /><label>Urgent ($ 40)</label>
<input type="checkbox" id="meetchk" name="meetchk" value="1" /><label>Meet ($ 60)</label>
</div>
<div>
<p>TOTAL</p>
<table id="items"></table>
<table id="total"></table>
</div>
JQ
$('#urgentchk').change(function() {
if(this.checked)
{
var content = "<tr id='one'><td>Urgent $ 40</td></tr>";
var prize = parseFloat($(this).attr('prize'));
$('#items').append(content);
}
else
{
$('#one').remove();
}
});
$('#meetchk').change(function() {
if(this.checked)
{
var content = "<tr id='two'><td>Meet $ 60</td></tr>";
var prize = parseFloat($(this).attr('prize'));
$('#items').append(content);
}
else
{
$('#two').remove();
}
});
Now, unfortunately, I have two problems that I do not know how to solve:
- Show the selected field (radiobutton) in the #items as done with the fields checkbox.
- Calculate the the price (sum) of the selected fields in the #total.
How could I do this? thanks