I've published an order page where I'm trying to have totals calculated on a button onclick event. Here is the code in the <head>: <script type="text/javascript"> function total() { var a=document.form1.blanketprice.value * "1"; var b=document.form1.namefee.value * "1"; var c=document.form1.dollprice.value * "1"; var d=document.form1.giftwrapprice.value * "1"; var totalcost= (a + b + c + d); document.form1.total.value = totalcost; } </script> Here is the code in the <body>: <td align="right" valign="middle" class="style2">Blanket Price: </td> <td colspan="3" align="left" valign="middle" class="style2"><input name="blanketprice" type="text" id="blanketprice" size="40"></td> </tr> <tr> <td align="right" valign="middle" class="style2">Embroidered Name Fee: </td> <td colspan="3" align="left" valign="middle" class="style2"><input name="namefee" type="text" id="namefee" size="40"></td> </tr> <tr> <td align="right" valign="middle" class="style2">Doll Price: </td> <td colspan="3" align="left" valign="middle" class="style2"><input name="dollprice" type="text" id="dollprice" size="40"></td> </tr> <tr> <td align="right" valign="middle"><span class="style2">Gift Wrap Price: </span></td> <td colspan="3" align="left" valign="middle"><span class="style2"> <input name="giftwrapprice" type="text" id="giftwrapprice" size="40"> </span></td> </tr> <tr> <td align="right" valign="middle"><strong>Order Total:</strong></td> <td colspan="3" align="left" valign="middle"><span class="style2"> <input name="total" type="text" id="total" size="40"> </span></td> </tr> <tr> <td width="33%" align="center" valign="middle"> </td> <td colspan="3" align="left" valign="middle"><input name="UpdateTotal" type="button" class="style7" id="UpdateTotal" onClick="total();" value="Update Total"></td> </tr> Here is the link url to the entire order form: http://www.branchouttemp2.biz/createyourblanket.php
What output are you getting? From a quick glance, you are converting numbers to strings every time that you multiply something by "1" Try cutting out the quotes from each IF that doesn't work try to see what your variables are storing with an alert box. For instance aler(document.form1.giftwrapprice.value ) will let you see what the value is.
Thanks for the ideas! Tried both -- Also, I couldn't get the aler() to show me anything (maybe I'm an idiot) Still not working. When I click the "update total" button, I get no output at all in the totalcost field. What I do get is an additional error on the page that says "The object does not support this method." assumably referring to the button. How does a button not support an onclick?? ARG.
sorry man, i meant to write alert(document.form1.giftwrapprice.value ) the parseInt should work. However, I looked at your page and for some reason there is a problem with finding the function total(). Change the name of total() to atotal(); and make the onClick ='atotal();' and it should work-- i just copied your page's html and it worked for me. At this point it will call the function properly but i didn't test to see if it gets the total so try those alert boex in the body of the function. Code (markup):