开发者

Multiplying two numbers using jquery ajax in mvc2 [closed]

开发者 https://www.devze.com 2023-03-25 19:46 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
$('#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'
0

精彩评论

暂无评论...
验证码 换一张
取 消