开发者

Replacing the Label Value with another value using Jquery

开发者 https://www.devze.com 2023-03-27 22:46 出处:网络
I am passing a value through Json to MVC View Page to change the current label value to the value passed through J开发者_高级运维son , Below is the code:

I am passing a value through Json to MVC View Page to change the current label value to the value passed through J开发者_高级运维son , Below is the code:

 .........
 return Json(new { name = Math.Round(discount), message = "Discount  :" + getVoucher.Discount + ""   });

 $("#promo").click(function () {
        var codenumber = $('#codeText').val();

        $.ajax({
            type:'POST',    
            url: this.href,
            cache: false,
            data: {input:$('#codeText').val(),amount:$('#checkoutAmount').val() },
             success: function (result) {
            alert(result.message);
            var totalamount = $(result);
           // $('#totalAmount').val(result.name);
            $('#checkoutAmount').val(result.name);
             $('#totalAmount').innerHTML = result.name;
        },
        error: function () {
            alert("error");
        }
        });
        return false;
    });

<label><b>Total Amount:</b></label> 
                  <label id="totalAmount"><%: String.Format("{0:c}", ViewBag.TotalAmount)%></label>

The totalAmount Value which is ViewBag.TotalAmount should be replaced by result.name. But the value is not replaced , it retains the same old value , when i use input html tag it works fine :

<%--<input type="text" id="totalAmount" value="<%: String.Format("{0:c}", ViewBag.TotalAmount)%>" />--%>

But the problem is I dont want to render the amount in the text field I want it to be shown as label text .

Cheers Thnx


Assumin that

result.name

has a value (did you check that in firebug?) you can try this

$('#totalAmount').html(result.name);
0

精彩评论

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