CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Master-Detail Form for Order Entry - Javascript formatting help

Print topic Send  topic

Author Message
infobih

Posts: 58
Posted: 12/30/2009, 3:42 AM

Hi all

Look at example pack "Master-Detail Form for Order Entry" on http://examples.codecharge.com/ExamplePack/OrderEntry/OrderEntry.php

How can force JavaScript to always show two decimal places for "Price" and "Total" as it is for "Unit Price", even if it is ex. 12.90 instead 12.9

This is javascript used in the page:

<script language="JavaScript" type="text/javascript">

function StrToFloat(str)
{
if (str.indexOf(",") != -1) {
str = str.replace(",",".");
}
var result = parseFloat(str);
if (isNaN(result)) {
result = 0.00;
}
return (result);
}

function Show_Total()
{
var TotalSum=0;
var Summ;
for(var i = 0; i < store_orders_itemsElements.length; i++){
Summ = StrToFloat(store_orders_itemsElements[store_orders_itemspriceID].value) *
StrToFloat(store_orders_itemsElements[store_orders_itemsquantityID].value);
TotalSum = TotalSum + Summ;
if (Summ == 0) {
store_orders_itemsElements[store_orders_itemsSumPriceID].value = "";
} else {
store_orders_itemsElements[store_orders_itemsSumPriceID].value = Math.round(Summ*100)/100;
}
}
document.store_orders_items.Total_price.value = Math.round(TotalSum*100)/100;
}
View profile  Send private message
computerman


Posts: 27
Posted: 01/15/2010, 3:32 PM

Check this out:
http://www.w3schools.com/jsref/jsref_tofixed.asp
_________________
"whoever is a cruel, must be an old downtrod who has got authority,
whoever is a downtrod, must be an old cruel who has lost authority. "
An Oriental Saying
View profile  Send private message
infobih

Posts: 58
Posted: 01/16/2010, 12:11 AM

Thank you for answer.

I did try this before. I think it will do it job - function (num.toFixed(2), but i dont know where to put exactly in my script. I am noy sucessfull.

Can you help if you know Javascript.
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.