javascript - Getting a syntax error, saying my function is undefined -


very unfamiliar javascript, i'm pretty sure should work of course isn't. little spotting error please.

function calcshipping() { var purchaseprice = document.input.purchaseprice.value; var shippingprice;  if (purchaseprice < 25) {     shippingprice = 1.5; } else {     shippingprice = (purchaseprice * .10 ) } var totalprice = (purchaseprice + shippingprice) document.input.total.value =      totalprice; } //--> </script>  <body> <h1>shipping , handling calculator</h1> <form name="input"> purchase price:<input type="text" name="purchaseprice" size="15"><br /> <input type="button" value="shipping calculation" onclick="calcshipping()"><br /><br       />     total cost:<input type="text" name="total" size="15"><br /> </form> 

you need separate lines here:

var totalprice = (purchaseprice + shippingprice) document.input.total.value =      totalprice; 

to

var totalprice = (purchaseprice + shippingprice); document.input.total.value = totalprice; 

your example code missing <script> tag might due pasting error. add 1 in before start of code if it's missing.

edit: can solve value error using parseint convert value of text field integer processing:

var purchaseprice = parseint(document.input.purchaseprice.value, 10); 

fiddle


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -