I'm trying to create a simple calculation. I have the calculation part working correctly but I want to compare the result and have a message appear based on the result. I've tried several examples such as:
if (P.toFixed(0)) == 1
$("#coolingneed").val('1 ton unit');
else
if (P.toFixed(0)) >= 2
$("#coolingneed").val('1.5 ton unit');
but nothing works. Actually the calculation will not perform when I try to add the comparison statements.
Suggestions?
<script type='text/javascript' src='
<h3>Cooling Calculator</h3>
<form >
<p> <input type="text" name="people" id="people" class="tonfield" />
Number of people you are cooling
</p>
<p> <input type="text" name="watts" id="watts" class="tonfield" />
Total wattage for all equipment in room
</p>
<p> <input type="text" name="sqft" id="sqft" class="tonfield" />
Square footage of room
</p>
<button class="smallButton" id="coolingcalc" onclick="return false">Tons of Cooling</button>
<input type="text" name="coolingneed" id="coolingneed" class="tonAnswer" />
</form>
<script type="text/javascript">
$("#coolingcalc").click(function(){
var L,P,n,c,dp;
L = parseInt($("#people").val()) * 600;
n = parseInt($("#watts").val()) * .34;
c = parseFloat($("#sqft").val())/250;
P = (L+n+c)/12000;
if(!isNaN(P))
{
$("#coolingneed").val(P.toFixed(0));
}
else
{
$("#coolingneed").val('There was an error');
}
return false;
});
</script>
if (P.toFixed(0)) == 1
$("#coolingneed").val('1 ton unit');
else
if (P.toFixed(0)) >= 2
$("#coolingneed").val('1.5 ton unit');
but nothing works. Actually the calculation will not perform when I try to add the comparison statements.
Suggestions?
<script type='text/javascript' src='
<h3>Cooling Calculator</h3>
<form >
<p> <input type="text" name="people" id="people" class="tonfield" />
Number of people you are cooling
</p>
<p> <input type="text" name="watts" id="watts" class="tonfield" />
Total wattage for all equipment in room
</p>
<p> <input type="text" name="sqft" id="sqft" class="tonfield" />
Square footage of room
</p>
<button class="smallButton" id="coolingcalc" onclick="return false">Tons of Cooling</button>
<input type="text" name="coolingneed" id="coolingneed" class="tonAnswer" />
</form>
<script type="text/javascript">
$("#coolingcalc").click(function(){
var L,P,n,c,dp;
L = parseInt($("#people").val()) * 600;
n = parseInt($("#watts").val()) * .34;
c = parseFloat($("#sqft").val())/250;
P = (L+n+c)/12000;
if(!isNaN(P))
{
$("#coolingneed").val(P.toFixed(0));
}
else
{
$("#coolingneed").val('There was an error');
}
return false;
});
</script>