SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Form Problems
-
Jul 15, 2002, 09:18 #1
- Join Date
- Jul 2002
- Location
- MT, USA
- Posts
- 44
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Jul 15, 2002, 23:03 #2
- Join Date
- Jan 2001
- Location
- Toronto
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Jul 16, 2002, 20:59 #3
- Join Date
- Jul 2002
- Location
- MT, USA
- Posts
- 44
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
nan error
i always get a NaN error, is this because it sees the numbers as words? because they are in quotes?
--Jetzy Jezter
"The future awaits."
-
Jul 16, 2002, 22:16 #4
- Join Date
- Jan 2001
- Location
- Toronto
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Jul 17, 2002, 08:36 #5
- Join Date
- Jul 2002
- Location
- MT, USA
- Posts
- 44
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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--Jetzy Jezter
"The future awaits."
-
Jul 17, 2002, 12:55 #6
- Join Date
- Jan 2001
- Location
- Toronto
- Posts
- 106
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
Bookmarks