# Thread: Form Problems

1. ## Form Problems

Go To http://www.rolandcheek.com/order_online.shtml

When you are there choose three books, in the first three drop downs

Then, enter a quantity for each. THis is where the first problem occurs. If a person were to want 2 of 1 kind of book , and the book cost 19.95, the form would put 39.9 in the Total area. It needs to be 39.90. Say the person wanted three books at 19.95 each, the total from the form would be 59.849999999999994, it needs to round that to 59.85.

The second error comes about when you click the "Get total!"
button. Instead of adding the numbers it sticks them side by side.

Please try this out and mabey even give the coding a look(parts of it are done with javascript)and tell me what you think i could do to fix it, or just give me any suggestions you have.

Thanks for your help,

Brandon

2. Hi Brandon,

For your second error, add parseFloat() to each of the statements you are adding.

total = parseFloat(document.form.total_1)+parseFloat(document.form.total_2)+parseFloat(document.form.total_3)+etc.etc.

As for 39.90 being displayed as 39.9, the only thing I can thing of is to manually check for the the number of characters after a period, then adding zero accordinly.

totalCentsArr = total.split(".");
totalCents = totalCentsArr[1];
if(totalCents.length == 1) total = total+'0';

OR, you can solve the above and the 59.849999999999994 problem by using this function: http://javascript.internet.com/forms...cy-format.html

Jon

3. ## nan error

i always get a NaN error, is this because it sees the numbers as words? because they are in quotes?

4. Most probably.

Try alerting isNaN(whateverNumber) in various stages to see where this is occuring.

parseFloat uses the first character as a guide. If the first character is NaN, the string is NaN.

Hope this helps.

5. ## uhm.....

i got past the decimal error thanks to the link you gave me and a lot of changes, but here is the link

http://www.rolandcheek.com/order_onlinetest.shtml

but im not sure bout the NaN thign

6. The totals you are adding cannot have a dollar sign, or they will be returned as NaN (not a number). By looking at the "Total" column, it looks as though they do have a dollar sign.

I think it'll be best to have only numbersin the form fields and have the dollar sign outside (like the Total Order field). Then, in your code and values you can avoid deling with the dollar sign altogther.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•