Hi,
I have a trouble. I have select option with value. I need to make sum of each of ths selct option. But when you select nothing happen.
<script>
$(document).ready(function() {
$("#products select").on("change", function() {
var id = this.value;
$.ajax({
url: "ajax.json",
method: "get",
data: "id=" + id,
success: function(response) {
//initialize totalPrice to 0 if doesn't contain a value
var totalPrice = $("#totalprice").val() !== "" ? parseInt($("#totalprice").val()): 0;
var datashow = response;//JSON.parse(response);
var price1 = parseInt(datashow[0].price);
/*var time1 = datashow[0].time;*/
//add the total price
$("input#totalprice").val(totalPrice + price1);
//Do something similar for time, I don't how you plan on parsing this?
/*$("input#totaltime").val(time1);*/
}
});
});
});
</script>
<div id="products">
<select id="product1" name="product1">
<option value="" selected="selected">-</option>
<option value='1'>1</option>
</select>
<select id="product2" name="product2">
<option value="" selected="selected">-</option>
<option value='2'>2</option>
</select>
<select id="product3" name="product3">
<option value="" selected="selected">-</option>
<option value='3'>3</option>
</select>
<select id="product4" name="product4">
<option value="" selected="selected">-</option>
<option value='4'>4</option>
</select>
<select id="product5" name="product5">
<option value="" selected="selected">-</option>
<option value='5'>5</option>
</select>
</div>
<input id="totalprice" type="text" name="totalprice" />
<!--input id="totaltime" type="text" name="totaltime" /-->