I thought I had it right but I've got an error where there is only text in a <td>... so have a look and tell me what ever is wrong with it.. as a whole.
I appreciate any help.HTML Code:<HTML> <HEAD> <TITLE>Fuel Economy</TITLE> <script type="text/javascript"> function updatesum() { if (document.form1.dist.value=="") { alert("Fill in the distance"); } if (document.form1.fuel.value=="") { alert("Fill in the Fuel"); } if (document.form1.cost.value=="") { alert("What is the cost of fuel?"); } var dist = (document.form1.dist.value); var fuel = (document.form1.fuel.value); var cost = (document.form1.cost.value); var total = fuel*cost; var kmplt = dist/fuel; var ltpdist = fuel/dist * 100; var mpg = (dist * 0.621) / (fuel * 0.624); document.write("<center><table border="1" bgcolor="gray"><tr><td>Total cost</td><td>$" + total.toFixed(2) + "</td><td rowspan="4" valign="middle"><b>Calculate<br>Fuel Economy</b></td></tr>"); document.write("<tr><td>Kilometers per litre used</td><td>" + kmplt.toFixed(2) + "</td></tr>"); document.write("<tr><td>Fuel consumed</td><td>" + ltpdist.toFixed(2) + "</td></tr>"); document.write("<tr><td>Miles per gallon travelled</td><td>" + mpg.toFixed(2) + "</td></tr></table></center>"); } </script> </HEAD> <BODY bgcolor="lightblue"> <center> <form name="form1"> <table border="1" cellpadding="10" bgcolor="gray"> <tr> <td>Distance traveled </td><td><input name="dist" size="5"> km</td><td rowspan="3" bgcolor="white"><center><font face="arial"><b>Calculate<br>Fuel Economy</b></font></center></td> </tr> <tr> <td>Fuel used </td><td><input name="fuel" size="5"> per litre</td> </tr> <tr> <td>Fuel cost </td><td><input name="cost" size="5"> per litre</td> </tr> <tr> <td colspan="3"> <input type="button" value="Calculate" onClick="updatesum"> <input type="reset" value="Reset"> </td> </tr> </font> </table> </form> </center> </BODY> </HTML>


LinkBack URL
About LinkBacks
Reply With Quote


