<?xml version = "1.0" encoding = "utf-8" ?>
<!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" >
<h1>
<strong> Totals the cost of the fruit you want!!!! </strong>
</h1>
<body>
<form id = "myForm" action = "" onsubmit = "alert('Your total cost is $' + totalCost);">
<label><input type = "checkbox" name = "fruitButton" id = ".59" value = ".59" />
Apples </label>
<label><input type = "checkbox" name = "fruitButton" id = ".49" value = ".49" />
Bananas </label>
<label><input type = "checkbox" name = "fruitButton" id = ".39" value = ".39" />
Oranges </label>
<input type = "submit" name = "submit" onclick = submit; />
</form>
<script type = "text/javascript" src = "total2.js" >
</script>
</body>
</html>
//total.js
//
var totalCost = 0;
function total()
{
//Which buttons are checked plus costs
var dom = document.getElementByID("myForm");
for(var index = 0; index < dom.fruitButton.length; index++)
{
if(dom.fruitButton[index].checked)
{
totalCost = totalCost + dom.fruitButton[index].value;
}
}
return totalCost;
}
//total2.js
var dom = document.getElementById("myForm");
dom.getElementById(".59").onclick = total;
dom.getElementById(".49").onclick = total;
dom.getElementById(".39").onclick = total;
dom.getElementById("myForm").onsubmit = total;

New Topic/Question
Reply



MultiQuote




|