I'm trying to make a form that will work out how much something will cost based on the options selected. I have managed to make it work successfully for 3 options however I can't figure out how to make it create the subtotal, this subtotal should add the variables "vpageprice" and "vmediaprice" and be displayed inside the cell with the id "st". Below is my code and heres a JSfiddle.
HTML
<div style="margin:auto;text-align:center;" id="form">
<table width="300" border="1" cellspacing="0" cellpadding="0">
<tr><th scope="col">Element</th><th scope="col">Type</th><th scope="col">Price</th></tr>
<tr><td>Media</td><td>
<select id="media">
<option value="0">None</option>
<option value="5">Audio</option>
<option value="10">Video</option>
<option value="12">Both</option>
</select></td>
<td id="mp"></td></tr>
<tr><td>Page Style</td><td>
<select id="pagestyle">
<option value="10">Seperate</option>
<option value="5">Content Change</option>
</select></td>
<td id="ps"></td></tr>
<tr><td>Pages</td><td>
<select id="pages">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select></td>
<td id="pp"></td></tr>
<tr><td colspan="2">Total</td><td id="st"></td></tr>
</table>
</div>
jQuery
$(document).ready(function(){
function mediaprice() {
var vmediaprice = $("#media").val();
$("#mp" ).html("£"+vmediaprice);
}
$("#form").change(mediaprice);
mediaprice();
function pagestyleprice() {
var vpagestyleprice = $("#pagestyle").val();
$("#ps" ).html("£"+vpagestyleprice+" per page");
}
$("#form").change(pagestyleprice);
pagestyleprice();
function pageprice() {
var vpageprice = ($("#pages").val())*($("#pagestyle").val());
$("#pp" ).html("£"+vpageprice);
}
$("#form").change(pageprice);
pageprice();
});
I hope someone can help me resolve this issue, if anyone has a better/easier way to make this form I will change what I have. Many thanks.