Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems inserting value with commas in between

Status
Not open for further replies.

garfield11

IS-IT--Management
Jul 4, 2002
44
SG
Hi all,

I have these 2 fields: Quantity(qty) and Total Price(total). I want to make my program to work as like when a user enters a quantity say 50, onchange it will auto compute the total price and also at the same time, if the amount is 4 digit say 1000 i want it to be displayed like this: 1,000.

Below codes work perfectly well,

BUT

when i insert the value into the database, it only insert 1 instead of 1,000....... eh can anyone pls advise.

Thanks and here are my codes:

function computeTotal()
{
var Total;
Total = eval(document.forms[1].unitPrice.value) * eval(document.forms[1].qty.value);
document.forms[1].total.value="";
document.forms[1].total.value=commas(round(Total,2));
}

function commas(num)
{
num=output=num.toString(),l=num.length;
for(var i=l;i>-1;i=i-3)
{
if(i!=0 && i!=l)
{
output=output.substring(0,i)+','+output.substring(i)
}
}
return output;
}
 
"BUT

when i insert the value into the database, it only insert 1 instead of 1,000....... eh can anyone pls advise"

You'll have to change your database field from an "number" field to a text field then you can enter "1,000", or you can convert the "1,000" before adding it to your database.

Do something like: replace(TotalValue,",","")
The replace function from VBScript inside an asp page will remove the comma.

"did you just say Minkey?, yes that's what I said."

MrGreed
 
>> BUT
>> when i insert the value into the database, it only
>> insert 1 instead of 1,000

That is a question for you database not javascript. Find the forum for your database here at Tek-tips. There are more database forums here then bombs have dropped on Iraq.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top