goldy300
New Member
- Messages
- 33
- Reaction score
- 0
- Points
- 0
I've been going through a few exercises and displaying the result on another page using document.write. I actually want to display the result in the text box at the bottom after the user hits the button. so onClick or onSubmit but I don't know how to display the total in that box.
I always appreciate your help guys!
Thanks again.
I always appreciate your help guys!
HTML:
<HTML>
<HEAD>
<TITLE> Car ownership costs </TITLE>
<script type="text/javascript">
function calculate()
{
document.form1.calculate.value = (document.form1.rego.value) + (document.form1.pink.value) + (document.form1.green.value) + (document.form1.insure.value) + (document.form1.rsfee.value) + ((document.form1.petorl.value)*52) + (document.form1.tyre.value) + (document.form1.fines.value) + ((document.form1.service.value)*2);
}
</script>
</HEAD>
<BODY bgcolor="#4809c7">
<font color="#ffffff" face="arial"><center><h1>Car Ownership Costs</h1></center>
<form name="form1">
<center>
<table border="0" cellpadding="10" bgcolor="white" cellspacing="0">
<tr>
<td colspan="2" bgcolor="#d7d7d7"><center>Anual Costs<br></center></td>
</tr>
<tr>
<td>Car Registration:</td><td><input name="rego" size="5"> per year</td>
</tr>
<tr>
<td>Pink Slip:</td><td><input name="pink" size="5"> per year</td>
</tr>
<tr>
<td>Green Slip:</td><td><input name="green" size="5"> per year</td>
</tr>
<tr>
<td>Comprehensive Insurance:</td><td><input name="pink" size="5"> per year</td>
</tr>
<tr>
<td>Road Service Fee:</td><td><input name="rsfee" size="5"> per year</td>
</tr>
<tr>
<td>Green Slip:</td><td><input name="green" size="5"> per year</td>
</tr>
<tr><td colspan="2" bgcolor="#d7d7d7"><center>Variable Costs</center></td></tr>
<tr>
<td>Petrol:</td><td><input name="rego" size="5"> per week</td>
</tr>
<tr>
<td>Tyre Replacement:</td><td><input name="tyre" size="5"> per year</td>
</tr>
<tr>
<td>Speeding fines:</td><td><input name="fines" size="5"> per year</td>
</tr>
<tr>
<td>Car Service:</td><td><input name="service" size="5"> per 6 months</td>
</tr>
<tr>
<td><input type="button" value="Calculate Total" name="calculate" onClick="calculate()"></td><!--This must be wrong-->
<td>$ <input ??total cost here?? </td><!-- I have no idea on how to display the total in a text box -->
</tr>
</table>
</center>
</form>
</font>
</BODY>
</HTML>
Thanks again.