Я работал над кодом для некоторых калькуляторов для бухгалтера. Похоже, что он отлично работает в Internet Explorer: вы набираете цифры и все это складываете, но в Safari и Firefox это похоже на то, что файл JavaScript не был распознан и просто прокручивается вверх до верхней части страницы.
Любая помощь будет принята с благодарностью.
JavaScript:
function Calculation()
{
var error_flag = false;
var error_string = "";
if (isNaN(document.calcfuel.mileage.value))
{
error_flag = true
error_string = error_string + "Non numeric mileage.\n"
}
if (isNaN(document.calcfuel.mpg.value))
{
error_flag = true
error_string = error_string + "Non numeric miles per gallon.\n"
}
if (isNaN(document.calcfuel.fuelprice.value))
{
error_flag = true
error_string = error_string + "Non numeric fuel price.\n"
}
if (error_flag)
alert(error_string);
else
{
var fuelcost = ((document.calcfuel.mileage.value / document.calcfuel.mpg.value) * 4.54 * document.calcfuel.fuelprice.value) / 100;
fuelcost = (parseInt(fuelcost * 100)) / 100;
if (isNaN(fuelcost))
{
error_string = "Incorrect data entered\n";
alert(error_string);
}
else
{
document.calcfuel.output_value.value=fuelcost;
return false;
}
}
}
HTML:
<!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" class="pageCalcPFuelcost" lang="en" xml:lang="en" id="sharedContentCalculators">
<head>
<script src="C:\Users\Faye\Desktop\calcs\calcs\fuel_cost.js" type="text/javascript">
</script>
<div id="calculator">
<form name="calcfuel" id="calcfuel">
<table border="0" cellpadding="0" cellspacing="0" width="428" class="bgColorContent">
<tr>
<td class="cornerTopLeft"><img src="/images/spacer.gif" alt="" width="8" height="32" border="0" /></td>
<td class="bgTop">How much do you spend on fuel in a year?</td>
<td class="cornerTopRight"><img src="/images/spacer.gif" alt="" width="8" height="32" border="0" /></td>
</tr>
<tr>
<td class="bgLeft"><img src="/images/spacer.gif" alt="" width="8" height="1" border="0" /></td>
<td class="bgColorContent"><br /><strong>With the fluctuating cost of fuel seemingly an ever-present news item, we thought that using our fuel cost calculator would show how much you are now spending on fuel.<br /><br /> Enter the number of miles you expect to drive in the next twelve months, the cost of fuel, less <acronym title="Value Added Tax">VAT</acronym> if you are <acronym title="Value Added Tax">VAT</acronym> registered and the mpg for your vehicle.</strong></td>
<td class="bgRight"><img src="/images/spacer.gif" alt="" width="8" height="1" border="0" /></td>
</tr>
<tr>
<td class="bgLeft"><img src="/images/spacer.gif" alt="" width="8" height="1" border="0" /></td>
<td class="bgColorContent">
<table align="center" cellpadding="0" cellspacing="5" border="0" width="360">
<tr>
<td align="right" class="bgColorContent">
<tr>
<td class="borderhorizontal" colspan="2"><img src="/images/spacer.gif" alt="" width="1" height="1" border="0" /></td>
</tr>
<tr>
<td class="bgColorContent" colspan="2"><img src="/images/spacer.gif" alt="" width="1" height="5" border="0" /></td>
</tr>
<tr>
<td class="bgColorContent" align="right"><label for="miles">Enter the number of miles per year you drive :</label></td>
<td class="bgColorContent"><input type="text" class="form" id="miles" name="mileage" value="12000" size="10" maxlength="6"></td>
</tr>
<tr>
<td class="bgColorContent" align="right"><label for="price_litre">Enter your normal price for a litre of fuel in pence:</label></td>
<td class="bgColorContent" align="right" valign="bottom"><input type="text" class="form" id="price_litre" name="fuelprice" value="135" size="10" /></td>
</tr>
<tr>
<td class="bgColorContent" align="right"><label for="mpg">Enter the <acronym title="Miles per Gallon">MPG</acronym> you average in your vehicle :</label></td>
<td class="bgColorContent"><input type="text" id="mpg" class="form" name="mpg" value="35" size="10" /></td>
</tr>
<tr>
<td class="bgColorContent" colspan="2"><img src="/images/spacer.gif" alt="" width="1" height="5" border="0" /></td>
</tr>
<tr>
<td colspan="2" align="right" class="bgColorContent"><input class="button" type="reset" name="Reset" value="Reset" /> <input class="button" type="button" name="Calculate" value="Calculate" OnClick="Calculation()">
</td>
</tr>
<tr>
<td class="bgColorContent" colspan="2"><img src="/images/spacer.gif" alt="" width="1" height="5" border="0" /></td>
</tr>
<tr>
<td align="right" class="bgColorContent"><strong><label for="todays_money">Fuel expenditure per year </label></strong></td>
<td align="right" valign="bottom" class="bgColorContent"><input type="text" id="todays_money" name="output_value" size="10" class="form" /></td>
</tr>
<tr>
<td class="bgColorContent" colspan="2"><img src="/images/spacer.gif" alt="" width="1" height="5" border="0" /></td>
</tr>
<tr>
<td class="borderhorizontal" colspan="2"><img src="/images/spacer.gif" alt="" width="1" height="1" border="0" /></td>
</tr>
<tr>
<td class="bgColorContent" colspan="2"><img src="/images/spacer.gif" alt="" width="1" height="5" border="0" /></td>
</tr>
</table>
</td>
<td class="bgRight"><img src="/images/spacer.gif" alt="" width="8" height="1" border="0" /></td>
</tr>
<tr>
<td class="bgLeft"><img src="/images/spacer.gif" alt="" width="8" height="1" border="0" /></td>
<td class="bgColorContent"><span class="sharedCalculatorsClassToHideText">You may be interested in <a href="/content/padvisor_home/keeping_fuel_costs_down.html">viewing our ideas</a> for keeping your fuel costs down.</a></span></td>
<td class="bgRight"><img src="/images/spacer.gif" alt="" width="8" height="1" border="0" /></td>
</tr>
<tr>
<td class="cornerBottomLeft"><img src="/images/spacer.gif" alt="" width="8" height="8" border="0" /></td>
<td class="bgBottom"><img src="/images/spacer.gif" alt="" height="1" border="0" /></td>
<td class="cornerBottomRight"><img src="/images/spacer.gif" alt="" width="8" height="8" border="0" /></td>
</tr>
</table>
</form>
<br />
</div>
</div>