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.

a live demo @ jsfiddle.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -