gathos Posted December 3, 2008 Share Posted December 3, 2008 ok so i have an estimate form that figures out how much a peice of glass costs per sq inch. but one of the variables are being multiplied by 10 thi sis my code: <script type="text/javascript"> var cprice = <? echo $_GET["cprice"]; ?>; function estimate() { var height = document.getElementById('glassheight').value; var height16 = document.getElementById('glassheight16').value; var totalheight = height + height16; var width = document.getElementById('glasswidth').value; var width16 = document.getElementById('glasswidth16').value; var totalwidth = width + width16; var ctotal = totalwidth * totalheight * cprice; var sqfttotal = ctotal / 144; document.write(height); document.write("<br>"); document.write(width); document.write("<br>"); document.write(totalwidth); document.write("<br>"); document.write(totalheight); document.write("<br>"); document.write(sqfttotal); document.write("<br>"); document.write(ctotal); document.write("<br>"); document.write(cprice); if (sqfttotal <= (cprice * 2)) { document.getElementById('cprice').value = (cprice * 2); } else { document.getElementById('cprice').value = MATH.round(sqfttotal*100)/100; }; }; </script> Width: <input type="text" name="glasswidth" id="glasswidth" /> <select name='glasswidth16' id='glasswidth16'> <option value='0'>Choose sixteenth</option> <option value='0'>0</option> <option value='0.0625'>1/16</option> <option value='0.125'>1/8</option> <option value='0.1875'>3/16</option> <option value='0.250'>1/4</option> <option value='0.3125'>5/16</option> <option value='0.375'>3/8</option> <option value='0.4375'>7/16</option> <option value='0.500'>1/2</option> <option value='0.5625'>9/16</option> <option value='0.625'>5/8</option> <option value='0.6875'>11/16</option> <option value='0.750'>3/4</option> <option value='0.8125'>13/16</option> <option value='0.875'>7/8</option> <option value='0.9375'>15/16</option> </select> <br /> X<br /> Height: <input type="text" name="glassheight" id="glassheight" /> <select name='glassheight16' id='glassheight16'> <option value='0'>Choose sixteenth</option> <option value='0'>0</option> <option value='0.0625'>1/16</option> <option value='0.125'>1/8</option> <option value='0.1875'>3/16</option> <option value='0.250'>1/4</option> <option value='0.3125'>5/16</option> <option value='0.375'>3/8</option> <option value='0.4375'>7/16</option> <option value='0.500'>1/2</option> <option value='0.5625'>9/16</option> <option value='0.625'>5/8</option> <option value='0.6875'>11/16</option> <option value='0.750'>3/4</option> <option value='0.8125'>13/16</option> <option value='0.875'>7/8</option> <option value='0.9375'>15/16</option> </select> <br /> <br /> <input type="button" onClick="estimate()" value="Estimate" /> </p> <br> <br> All Clear Plain Glass <input type="text" name="cprice" id="cprice" /></td> i haven't even got to the if statement yet, because when i test out the variables (the document.write section) totalheight and totalwidth are being times by 10. IE: i put in 30 and 300 is displayed for those 2. please help, i need a second pair of eyes to help me find my bug. thanks ahead of time, gathos Quote Link to comment Share on other sites More sharing options...
xtopolis Posted December 3, 2008 Share Posted December 3, 2008 I didn't check the math, but I can fix your javascript errors: var totalheight = height + height16; It is concatenating because height and height16 are both strings. Typecast them to integers by putting a + in front var totalheight = +height + +height16; OR Parse them as ints var height = parseInt(document.getElementById('glassheight').value); The same is for width. Quote Link to comment Share on other sites More sharing options...
gathos Posted December 3, 2008 Author Share Posted December 3, 2008 thank you, converting to an integer did help, i realized being a string it was litteraly adding the 0 from my other input select's. and also i figured out that there was another problem, with my math.round() I had to put it onto a seperate line first, then i was able to output it. thanks again and later days, gathos Quote Link to comment Share on other sites More sharing options...
xtopolis Posted December 4, 2008 Share Posted December 4, 2008 Oh yea, I forgot to add that MATH should have been Math... forgot that... but since you got it to work, no worries. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.