Having trouble with this code. I used to get the answer to come through with an alert message. Then I altered some of the validation and now I can no longer return the miles per gallon. I'm not sure if I'm sending the variable to the validation function correctly either. I would like to assign the value to the last text box in the form if possible. Any hints or suggestions? Thanks Chris.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Gas Mileage</title>
<style type="text/css">
body
{
background-image:url(brushed-silver-metallic-background.jpg);
background-repeat: space;
font:'cursive';
font-size:36px;
color:#C43D1E;
font-weight:bold;
}
form
{
border-style:solid;
border:medium;
border-color:#87E1F4;
float:left;
padding:250px;
height:300px;
background-image:url(gas-mileage.jpg);
/*opacity:.5;*/
background-repeat:no-repeat;
background-position:center;
}
input
{
border-style:solid;
border:#27DFD5;
border-width:medium;
background:#000;
font:'arail';
color:#FFF;
}
input:hover
{
border-style:solid;
border-width:medium;
border:#F00;
background:#FFF;
border-color:#f00;
color:#F00;
}
button
{
font-size:26px;
border-style:solid;
border:#27DFD5;
border-width:medium;
background:#000;
font:'arail';
color:#FFF;
}
button:hover
{
font-size:26px;
border-style:solid;
border:#F00;
border-width:medium;
background:#FFF;
border-color:#f00;
color:#F00;
}
p
{
border-style:solid;
border:medium;
border-color:#87E1F4;
float:left;
padding:250px;
height:300px;
background-image:url(gas-mileage.jpg);
/*opacity:.5;*/
background-repeat:no-repeat;
background-position:center;
}

</style>
<script type="text/javascript">
//clear the text values
function clearIt(a)
{

if (a==1)
{
if (document.getElementById("starting").value == "ENTER INFO")
{
document.getElementById("starting").value="";
document.getElementById("starting").value="";
}
}
else if (a==2)
{

if (document.getElementById("ending").value == "ENTER INFO")
{
document.getElementById("ending").value="";
}
}
else
{
if (document.getElementById("gas_used").value == "ENTER INFO")
{
document.getElementById("gas_used").value="";
}

}
}

function calcMpg()
{
window.alert("calculating your mles per gallon")
var starting_mileage = document.getElementById("starting").value;

var ending_mileage = document.getElementById("ending").value;
var gallons = document.getElementById("gas_used").value;
var valid = isNumber(starting_mileage, ending_mileage, gallons);
if (valid == false)
{
alert("please enter only number values into the form")
exit;
}
if (gallon < 0 || ending_mileage - starting_mileage < 0)
{
alert("you must have travelled a positive number of miles and used gas to calculate this value")
exit;
}
var total_gas = (ending_mileage - starting_mileage)/gallons;
alert(total_gas);
document.getElementById("mpg").value = total_gas;

function isNumber(x, y , z)
{
if(x == Nan())
return false;
if(y == Nan())
return false;
if(z==Nan())
return false;
else
return true;
}

}
</script>

</head>

<body>
<br />
<form name="gas_form" id="gas_form">
<label>
Enter your staring mileage here:
<input type="text" id="starting" name="starting" value="ENTER INFO" max="10" onfocus="clearIt(1)" />
</label>
<br />
<label>
Enter your ending mileage here:
<input type="text" id="ending" name="ending" value="ENTER INFO" max="10" onfocus="clearIt(2)" />
</label>
<br />
<label>
Enter your gallons of gas used here:
<input type="text" id="gas_used" name="gas_used" value="ENTER INFO" max="3" onfocus="clearIt(3)" />
</label>
<br />
<hr />
<div align="center">CLICK HERE &nbsp;<button onclick="calcMpg()" >GO!</button>
</div>
<label>
The miles per gallon for your vehicle this trip is:
<br />
<input type="text" id="mpg" name="mpg" />
</label>
</p>
</label>
</body>
</html>