javascript - Jquery returns NaN with price -
hi trying work out total price in jquery
i have try
full jquery
this jquery changing price in get_price have select statement echoing price echo $row2['price'];
the way works when every change length
price change
so in pricetag example 40.00
without £
"#pricetag somelike £40.00
" need rid of £
in #pricetag
before executing parseint()
. this:
var price = '\u00a3' + (parseint($('#pricetag').text().replace(/\u00a3/, ''), 10) * qty);
parseint()
searches digits starting beginning of string, , cuts search @ first non-digit found. in case first character £
, parsefloat()
returns nan
, produces nan
when used *
.
edit
what ever have (or don't have anything) in front of numbers in #pricetag
, can use remove it:
var price = '\u00a3' + parseint($('#pricetag').text().replace(/^\d/, ''), 10) * qty;
also notice, have validate qty
before using within calculations.
Comments
Post a Comment