469,315 Members | 1,601 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

JS Calculation Not Functioning

I've got some code that is supposed to calculate some values on a form and generate a total. It seems like it should work but it's definetly not, I am getting objected expected errors from the line(~26) with the onChange event, but I can't see that anything is missing.
Any help is appreciated.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>IOCC</title>
  3. <script> 
  4. <!--
  5. function InvoiceTotal(form)
  6.     {
  7.     var a = (form.#tickets.value != '') ? parseFloat(form.#tickets.value) : 0; if (isNaN(a)) a = 0;
  8.     var b = (form.adprice.value != '') ? parseFloat(form.adprice.value) : 0; if (isNaN(b)) b = 0;
  9.     var c = (form.chprice.value != '') ? parseFloat(form.chprice.value) : 0; if (isNaN(c)) c = 0;
  10.     var d = (form.chtickets.value != '') ? parseFloat(form.chtickets.value) : 0; if (isNaN(d)) d = 0;
  11.     var total = (a * b) + (c * d);
  12.     form.T_amt.value = total.toFixed(2);
  13.  
  14. } -->
  15.  </script>
  16. </head>
  17. <body>
  18. <FORM method="post" action="/randompathtononexistentscript.php">
  19. <label><input type="hidden" name="adprice" value="35" id="adprice"></label>
  20. <label><input type="hidden" name="chtickets" value="0" id="chtickets"></label>
  21. <label><input type="hidden" name="chprice" value="0" id="chprice"></label>
  22. <TR><TD ALIGN=left COLSPAN="2"><p>&nbsp;</p>
  23.   <p>&nbsp;</p></TD>
  24. </TR>
  25.  
  26. <TR><TD ALIGN=left><FONT FACE="Arial" SIZE="1">Number of Tickets</FONT></TD><TD ALIGN=left><label><INPUT NAME="#tickets" TYPE="TEXT" value="0" SIZE="4" id="#tickets" onChange="InvoiceTotal(this.form);"/></label>
  27.  
  28.  
  29. <TR><TD ALIGN=left><FONT FACE="Arial" SIZE="1">Purchase Amount </FONT></TD><TD ALIGN=left><font size="-1" face="Arial">$</font><label><INPUT NAME="T_amt" TYPE="TEXT" ID="T_amt"></label>  <FONT FACE="Arial" SIZE="1"><br></label>
  30.   </FONT></TD></TR><TR><TD ALIGN=left COLSPAN="2">&nbsp;</TD></TR>
  31.  
  32.  
  33. <TR><TD ALIGN=center VALIGN=middle><INPUT NAME="submit button" TYPE="SUBMIT" VALUE="Submit">
  34.  
  35. </FORM></TD></TR></TABLE>
  36. </TD></TR></TABLE>
  37.  
  38. </body>
  39. </html>
  40.  
Oct 17 '07 #1
1 980
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

I think the # is causing the problem. Replace it with 'NoOf' or something similar instead.
Oct 18 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by cdelaney | last post: by
4 posts views Thread by Michiel Alsters | last post: by
4 posts views Thread by vg-mail | last post: by
5 posts views Thread by The alMIGHTY N | last post: by
5 posts views Thread by =?Utf-8?B?amVsbGU3OQ==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.