Ive a textbox with id f开发者_StackOverflow社区nlprce I want to retrieve its value on an event, subtract 50 from it and update it to the latest value, ive this piece of code to work over:
function updateDiscount() {
    var iniprce = parseInt($("#fnlprce").text());
    var fnlprce = iniprce-50;
    $("#dscntdprce").html("Price: " + fnlprce + ");
    $("fnlprce").html(fnlprce);
}
But something getting wrong as it is showing, ‘NaN’ in the output, guidance please :)
Change
var iniprce = parseInt($("#fnlprce").text());
to
var iniprce = parseInt($("#fnlprce").val());
because val() is current value of that textbox.
Besides that, change
$("#dscntdprce").html("Price: " + fnlprce + ");
to
$("#dscntdprce").html("Price: " + fnlprce);
because yours one have syntax error
Use .val() instead of .text() as an input's value is found in its value= attribute, and not as a text node inside of it.
function updateDiscount() {
    var iniprce = parseInt($("#fnlprce").val(), 10);
    var fnlprce = iniprce - 50;
    $("#dscntdprce").html("Price: " + fnlprce);
    $("#fnlprce").html(fnlprce);
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论