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!

What's wrong with this code?

Status
Not open for further replies.

Laura2

IS-IT--Management
Aug 13, 2002
99
US
I have a form that has a base amount field and two tax amount fields. I'm trying to have them added together in the Total Field. It's adding the base with the gst but the pst is producing an error. Does anyone know why?

<input type=&quot;text&quot; id=&quot;Base_Amt_1&quot; size=&quot;12&quot; value=&quot;0&quot; onBlur=&quot;CreditCard.TotalDollars.value=parseFloat(CreditCard.Base_Amt_1.value)+parseFloat(CreditCard.GST1.value)+parseFloat(CreditCard.PST1.value);return true;&quot;>&nbsp;&nbsp;&nbsp;

<input type=&quot;text&quot; id=&quot;GST1&quot; size=&quot;8&quot; value=&quot;0&quot; onBlur=&quot;CreditCard.TotalDollars.value=parseFloat(CreditCard.Base_Amt_1.value)+parseFloat(CreditCard.GST1.value)+parseFloat(CreditCard.PST1.value);return true;&quot;>

<input type=&quot;text&quot; id=&quot;PST1&quot; size=&quot;8&quot; value=&quot;0&quot; onBlur=&quot;CreditCard.TotalDollars.value=parseFloat(CreditCard.Base_Amt_1.value)+parsefloat(CreditCard.GST1.value)+parseFloat(CreditCard.PST1.value);return true;&quot;>

<input type=&quot;text&quot; id=&quot;TotalDollars&quot; size=&quot;16&quot; value=&quot;0&quot; disabled=&quot;disabled&quot; onfucus=&quot;CreditCard.TotalDollars.blur();return false;&quot;></p>

A million thank you's in advance!

Laura.
 
make sure your form is named CreditCard,
and in PST1:
parsefloat
should be
parseFloat

case-sensitive

also in TotalDollars,
onfucus
should be
onfocus

=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Thanks Jeff. It was the parseFloat case sensitive thing.

Laura.
 
Laura,

In your PST1 onclick event, you call the function &quot;parsefloat&quot;. Ain't no such thing. It's &quot;parseFloat&quot;. Case: it's not juts for breakfast anymore. [lol]

But don't feel bad, it took me too long to find the little ragamuffin of an error!

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Oooooh, Jeff beat me to it! [lol]

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Okay guys, how do I make say 10 lines of base amounts along with taxes? So the form would allow 10 different items essentially. I thought I would just have to name my id's with a &quot;2&quot; then for the next line item a &quot;3&quot; as this:

<input type=&quot;text&quot; id=&quot;Base_Amt_2&quot; size=&quot;12&quot; value=&quot;0&quot; onBlur=&quot;CreditCard.TotalDollars2.value=parseFloat(CreditCard.Base_Amt_2.value)+parseFloat(CreditCard.GST2.value)+parseFloat(CreditCard.PST2.value);return true;&quot;>

<input type=&quot;text&quot; id=&quot;GST2&quot; size=&quot;8&quot; value=&quot;0&quot; onBlur=&quot;CreditCard.TotalDollars2.value=parseFloat(CreditCard.Base_Amt_2.value)+parseFloat(CreditCard.GST2.value)+parseFloat(CreditCard.PST2.value);return true;&quot;>

<input type=&quot;text&quot; id=&quot;PST2&quot; size=&quot;8&quot; value=&quot;0&quot; onBlur=&quot;CreditCard.TotalDollars2.value=parseFloat(CreditCard.Base_Amt_2.value)+parseFloat(CreditCard.GST2.value)+parseFloat(CreditCard.PST2.value);return true;&quot;>

<input type=&quot;text&quot; id=&quot;TotalDollars2&quot; size=&quot;16&quot; value=&quot;0&quot; disabled=&quot;disabled&quot; onfocus=&quot;CreditCard.TotalDollars2.blur();return false;&quot;>&nbsp;&nbsp;&nbsp; </p>

Am I doing something wrong?

Laura.
 
Laura,

If you're talking about 10 different text fields and the onclick operation is the same for all of them (sum all ten fields, then stuff the answer into the 11th field), then for pete's sake make a single Summation() function and for each onclick, just call Summation()

Summation() would basically be document.FormName.AnswerTXT.value=parseFloat(document.FormName.Value01TXT.value)+parseFloat(document.FormName.Value02TXT.value)+parseFloat(document.FormName.Value03TXT.value)+parseFloat(document.FormName.Value04TXT.value)+parseFloat(document.FormName.Value05TXT.value)+parseFloat(document.FormName.Value06TXT.value);

and so on.

At least that way, whenever you add a filed, you only have to change one function.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Thanks Edward but that's a bit advanced for me (just a beginner). Would my code above still work in theory?

Laura.
 
My issue is that this is in a table format. Hence each row has a total at the end. And then each total is further totalled at the bottom of that column. I don't want to add every field in the table. Just the fields in each row. I think using the method above will not acheive that. Am I right?

Laura.


























































 
Well, here's the problem. I would be happy to offer you a fully functional example, except I can't make the example work.

I'm stumped. maybe someone can help: thread216-587494

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Thanks Edward. I found the issue with the code. I had duplicate names throughout the rows. My last and final issue is that I have a grand total at the bottom that needs to add up all of the totaldollars but am unable to get that to work either. This is a very interesting language! :)

Laura.
 
Laura,

Follow the thread link I posted. There is an example of basically what I'm talking about.

If you know that all your values will be even cents values, you can avoid floating point errors by multiplying everything by a hundred and doing your operations using Integer functions, then manually inserting a decimal before display. I suppose you could also divide by a hundred, but there's no guarantee that 10010 divided by a hundred will give you 100.10 or 100.10000000000000002

I'm so annoyed at JavaScript right now because of this FP stuff...

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top