I am not sure by your question if you want to add it to the db on the selection... that would require a simple but different code. This will accomplish what you are asking.
You do not need a form... just the selection boxes. If you notice I encased each piece of html in an echo tag... this writes a minimized code to the browser.
You have to id each selection box as follows:
HTML
echo '<select id="this_postage" name="Postage">';
echo '<option value="14">1st Class</option>';
echo '<option value="8">2nd Class</option>';
echo '<option value="22">Next Day Delivery</option>';
echo '<option value="0">Click And Collect</option>';
echo '</select>';
echo '<select id="this_type" name="Type">';
$type = "SELECT * FROM $category order by id";
$item = mysql_query($type);
while ($typeitem = mysql_fetch_assoc($item)) {
echo '<option value='.$typeitem[price].'>'.$typeitem[type].'</option>';
}
echo '</select>';
echo '<div id="total_spend"></div>';
Notice the div with id="total_spend".
JQUERY
$(function() {
$( "#this_type" ).change(function(){
var total_spend = parseInt($('#this_postage').val()) + parseInt($('#this_type').val());
$('#total_spend').html('Total: £'+total_spend);
});
When the user selects the Type the jQuery will pick up the change and get the values of both the postage and type and add them and then render the total in the <div id="total_spend">Total: £TOTAL HERE</div>
THIS CODE WILL SEND TO DB:
Again no form tag required:
HTML:
Added hidden input to hold processing URL
echo '<input type="hidden" id="updateURL" value="PATH-TO-PHP-PROCESSING-FILE.PHP">';
echo '<select id="this_postage" name="Postage">';
echo '<option value="14">1st Class</option>';
echo '<option value="8">2nd Class</option>';
echo '<option value="22">Next Day Delivery</option>';
echo '<option value="0">Click And Collect</option>';
echo '</select>';
echo '<select id="this_type" name="Type">';
$type = "SELECT * FROM $category order by id";
$item = mysql_query($type);
while ($typeitem = mysql_fetch_assoc($item)) {
echo '<option value='.$typeitem[price].'>'.$typeitem[type].'</option>';
}
echo '</select>';
echo '<div id="total_spend"></div>';
JQUERY:
$(function() {
$( "#this_type" ).change(function(){
var url = $('#updateURL').val();
var postage = parseInt($('#this_postage').val());
var type = parseInt($('#this_type').val());
var total_spend = (postage + type);
var postit = $.post( url, {
custom_block_name:custom_block_name,
postage:postage,
type:type
});
postit.done(function( data ) {
alert(data);
$('#total_spend').html('Total: £'+total_spend);
});
});});
Treat the processing php as you would with the post method. At the bottom under the mysql update code you can
echo 'Whatever Message you want to render in the alert message here.';
If you do not want an alert remove it from the jquery
TO CALL jQUERY
...?>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$(function() {
$( "#this_type" ).change(function(){
var total_spend = parseInt($('#this_postage').val()) + parseInt($('#this_type').val());
$('#total_spend').html('Total: £'+total_spend);
});
</script>