Thanks in advance for the help.
I am very new to JavaScript. I am interested in learning how to properly write it. I was wanting to start with something relatively simple, but I find myself trying to pull out my hair to make the script work properly. :p
All I was trying to do is write a script that would allow a user to place a number in a text box, and when the user hits submit, a JavaScript function would calculate shipping and handling. Unfortunately, the script keeps wanting to join two variables together instead of performing the operation. Any help would be appreciated.
I am also open for suggestions on how to clean up my script because I know it is sloppy, and probably has a lot of unnecessary lines, but I am new at this.
Here is my code:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “
<html xmlns=”
<head>
<script type=”text/javascript”>
function shippingHandling() {
var purchasePrice = document.calcShipping.purchase_price.value;
var shippingHandling = 1.50;
var grandTotal = purchasePrice + shippingHandling;
var newPrice = purchasePrice + addShipHand;
var addShipHand = purchasePrice * 10/100;
if(purchasePrice <= 25) {
window.alert(“Your total cost is $” + purchasePrice + ” plus $” + shippingHandling + “, which is equal to $” + grandTotal + “”);
return true;
}
if(purchasePrice > 25) {
window.alert(“Your total cost is $” + purchasePrice + ” plus $” + addShipHand + “, which is equal to $” + newPrice + “”);
return true;
}
}
</script>
</head>
<body>
<form name=”calcShipping” action=”” onsubmit=”return shippingHandling()” method=”post”>
<table>
<tr>
<td>Purchase Price:</td><td><input type=”text” name=”purchase_price”></td>
</tr>
<tr>
<td> </td><td><input type=”submit” value=”Submit”></td>
</tr>
</table>
</form>
</body>
</html>