[thelist] JavaScript Question

John Hicks johnlist at gulfbridge.net
Tue May 2 13:32:27 CDT 2006


Jay Blanchard wrote:
> I have a calc that I am doing by echoing JavaScript with PHP. It work
> just dandy, but I need to format the result with two decimal places. I
> have searched the web (and I have seen toFixed, etc.) but the functions
> will not work with the calc;
> 
> echo "<input type=\"text\" name=\"phoneQuant$phoneLine\" size=\"3\"
> maxlength=\"2\" style=\"color: #000000; background-color: #FFFFCC;
> text-align: right;\"
> onkeyup=\"document.dealerOrder.phoneTotal$phoneLine.value =
> (document.dealerOrder.phoneQuant$phoneLine.value *
> document.dealerOrder.dealerCost$phoneLine.value)\">";
> 
> It is just a formatting issue for display. I have tried adding + ".00"
> etc...but no joy. It would be nice to be able to do something like
> 
> document.dealerOrder.phoneTotal$phoneLine.value.".00" but we all know
> that that does not work. Can someone point me in the right direction
> without having to cobble together a bunch of code?

x = (Math.round(y * 100) / 100).toFixed(2);

or

onkeyup=\"document.dealerOrder.phoneTotal$phoneLine.value =
(Math.round(document.dealerOrder.phoneQuant$phoneLine.value *
document.dealerOrder.dealerCost$phoneLine.value) / 100).toFixed(2); \">";

-J




More information about the thelist mailing list