jovi
06-24-2012, 05:55 PM
I am very new to JavaScript, and this is my first attemp at creating a shipping calculator. The doctype must be XHTM Strict, so I am using id= in the form fields rather than name. However, my alert box will not pop up unless i change it to transitional and change the id to name....i am going nuts trying to figure this out. Any help would be greatly appreciated.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Calculate Shipping</title>
<script type="text/javascript">
/* <![CDATA[ */
function calculateshipping()
{
var salesprice = parseFloat(document.calcship.price.value);
var salestotal = salesprice;
if (salesprice <= 25)
salestotal += 1.5;
else
salestotal += salesprice * 1.1;
window.alert("Your total cost including shipping is $" + salestotal);
}
/* ]]> */
</script>
</head>
<body>
<h1>Calculate Shipping and Handling</h1>
<form action="" id="calcship">
<p>Please enter the Purchase Price: <input type="text" id="price" /></p>
<p><input type="button" value="Calculate Shipping and Handling" onclick="calculateshipping()" /></p>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Calculate Shipping</title>
<script type="text/javascript">
/* <![CDATA[ */
function calculateshipping()
{
var salesprice = parseFloat(document.calcship.price.value);
var salestotal = salesprice;
if (salesprice <= 25)
salestotal += 1.5;
else
salestotal += salesprice * 1.1;
window.alert("Your total cost including shipping is $" + salestotal);
}
/* ]]> */
</script>
</head>
<body>
<h1>Calculate Shipping and Handling</h1>
<form action="" id="calcship">
<p>Please enter the Purchase Price: <input type="text" id="price" /></p>
<p><input type="button" value="Calculate Shipping and Handling" onclick="calculateshipping()" /></p>
</form>
</body>
</html>