tags:

views:

24

answers:

4

I have:

 TotalPrice = parseInt(TotalPrice*100)/100;
 $('input[name=EstimatedPrice]').val(TotalPrice);
 $('#EstimatedPriceDisplay').text(TotalPrice);

and I'm getting two warnings from lint.

  1. val() called incorrectly

  2. text() called incorrectly.

I was able to eliminate the text() called incorrectly error by doing the following:

$('#EstimatedPriceDisplay').text('' + TotalPrice);

But that seems kinda kludgy to me.

+2  A: 

Doing:

$('#EstimatedPriceDisplay').text('' + TotalPrice);

should be fine or you can use the toString method:

$('#EstimatedPriceDisplay').text(TotalPrice.toString());
Sarfraz
I like being able to upvote everyone who answers!
cf_PhillipSenn
+1  A: 

Do you want to support IE <5.5? If not, try to use the .toFixed() method, which returns a string and rounded to the specified decimal place.

 TotalPrice = TotalPrice.toFixed(2);
KennyTM
Ooh. I hate making decisions about who should get the rep!
cf_PhillipSenn
+1  A: 

Since you're reusing the variable, I'd make it a String when the value is assigned.

TotalPrice = (Math.round(TotalPrice*100)/100) + '';

This way you only need to do it once, and it is not cluttering .val() and .text()

$('input[name=EstimatedPrice]').val(TotalPrice);
$('#EstimatedPriceDisplay').text(TotalPrice);

EDIT: Changed to Math.round() to get proper up/down rounding.

patrick dw
Oh!I never thought .val() wanted a string parameter!I think my old school thinking is getting in my way.
cf_PhillipSenn
A: 
 $('input[name=EstimatedPrice]').val(TotalPrice.toFixed(2));
 $('#EstimatedPriceDisplay').text(TotalPrice.toFixed(2));
cf_PhillipSenn