I've started to make a profit management system for my mum, which recently got involved with vending machines, so I decided to make it using jquery. I think most of my code it right, but can someone check it out to see what's wrong.
What's wrong, is that when a change is detected, instead of filling the revenue and profit boxes with their respective numbers, it fills them with "NaN." Can someone please tell me why this is happening and what I need to do to stop it?
Code:
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="jquery-1.2.1.js" type="text/javascript" charset="utf-8"></script>
<script src="typewatch1.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function(){
// Set Variables
// Text field variables
var NoOfPacks
var SnacksPerPack
var PackPrice
var SnackSellPrice
var SnacksSold
// Eval Variables
var TotalSnacks = eval("NoOfPacks*SnacksPerPack");
var TotalPrice = eval("NoOfPacks*PackPrice");
var SingleSnackPrice = eval("PackPrice/SnacksPerPack");
var Revenue = eval("SnackSellPrice*SnacksSold");
var Profit = eval("Revenue-TotalPrice");
// Detect change in "packs" input and set variable
$('input[name="packs"]').change(function(){
NoOfPacks = $('input[name="packs"]').val();
$('input[name="revenue"]').val(Revenue);
$('input[name="profit"]').val(Profit);
});
// Detect change in "perpack" input and set variable
$('input[name="perpack"]').change(function(){
SnacksPerPack = $('input[name="perpack"]').val();
$('input[name="revenue"]').val(Revenue);
$('input[name="profit"]').val(Profit);
});
// Detect change in "packprice" input and set variable
$('input[name="packprice"]').change(function(){
PackPrice = $('input[name="packprice"]').val();
$('input[name="revenue"]').val(Revenue);
$('input[name="profit"]').val(Profit);
});
// Detect change in "sellprice" input and set variable
$('input[name="sellprice"]').change(function(){
SnackSellPrice = $('input[name="sellprice"]').val();
$('input[name="revenue"]').val(Revenue);
$('input[name="profit"]').val(Profit);
});
// Detect change in "itemssold" input and set variable
$('input[name="itemssold"]').change(function(){
SnacksSold = $('input[name="itemssold"]').val();
$('input[name="revenue"]').val(Revenue);
$('input[name="profit"]').val(Profit);
});
});
</script>
<title>Vending Profit Calculator</title>
</head>
<body>
<div id="container">
<h1>Vending Machine Profit Calculator</h1>
<div id="options">
<label for="packs">How Many Packs? </label><input type="text" name="packs" /><br/>
<label for="perpack">How Many Snacks/Drinks Per Pack: </label><input type="text" name="perpack" /><br/>
<label for="packprice">Pack Price: $</label><input type="text" name="packprice" /><br/>
<label for="sellprice">Snack/Drink Selling Price: $</label><input type="text" name="sellprice" /><br/>
<label for="itemssold">Snacks/Drinks Sold: </label><input type="text" name="itemssold" /><br/><br/>
</div>
<div id="results">
<label for="revenue">Total Revenue: </label><input type="text" name="revenue" /><br/>
<label for="profit">Total Profit: </label><input type="text" name="profit" />
</div>
</div>
</body>
</html>
What's wrong, is that when a change is detected, instead of filling the revenue and profit boxes with their respective numbers, it fills them with "NaN." Can someone please tell me why this is happening and what I need to do to stop it?