Multiplying two numbers using jquery ajax in mvc2 [closed]
$('#txtDistance').change(function() {
/*
$.getJSON('/MYKPortal/Conveyance/GetRateByConveyanceType', { role: $("#ddlTypes").val() }, function(开发者_如何转开发rate) {
$("#txtRate").val(rate.rate);
});
*/
var distance = $(parseInt("#txtDistance").val());
var rate = $(parseFloat("#txtRate").val());
//var amount = $("#txtAmount").val(distance * rate);
$.ajax({
type: 'POST',
data: JSON.stringify(amount),
contentType: 'application/json',
dataType: 'json',
success: function(result) {
$("#txtAmount").val(distance * Rate);
}
});
});
jQuery does unfortunately not support a multiplication function. This means we have to resort to normal JavaScript (I apologise.. I'm sure John Resig is working on something...)
In the mean time, I think this does what you want, but as you didn't ask a question, I'm guessing:
var distance = parseInt($("#txtDistance").val(), 10);
var rate = parseFloat($("#txtRate").val());
var amount = distance * rate;
$("#txtAmount").val(amount);
Remember to specify a radix for the parseInt
function
Try:
var distance = parseInt($("#txtDistance").val());
var rate = parseFloat($("#txtRate").val());
... and remember Javascript is case sensitive:
$("#txtAmount").val(distance * rate); // lower-case 'r'
精彩评论