jamemiddz
10-16-2003, 07:25 AM
Can anyone help me out with my script?
Ive put this together, I just a begginers with all this javascript stuff. I need to cause the final figure to read out in £'s and pence, i.e. £35.50 and not £35.5. I think that I need to incorporate another 'MATH' command, but I'm not sure how to......any ideas?
(this bit goes into the head)
<SCRIPT language=JavaScript>
/*
James Middleton - calculator
*/
<!--
function perc1() {
/* get value of property */
propertypc = document.form1.propertypc.value/100;
propertyval = propertypc*document.form1.propertyval.value
/* get value of contents */
contentpc = document.form1.contentpc.value/100;
contentval = contentpc*document.form1.contentval.value;
bothval = propertyval + contentval
premium = bothval / 100 * 5 + bothval
premium = Math.round(premium);
document.form1.final.value = "£" + premium
}
//-->
</script>
(This bit goes into the body)
<table width="400" border="0" cellspacing="0" cellpadding="10" height="250"><tr>
<td colspan="2" background="../images/darkgreen.gif">
<div align="right"><B><span class="Heading">Insurance Calculator</span></B></div></td></tr><tr>
<td width="50%" background="../images/lightgreen.gif">
<div align="right">Property Value = <input type="hidden" value="0.18" border="0" name=propertypc></div></td>
<td width="50%" background="../images/darkgreen.gif">£ <INPUT size=10 name=propertyval tabindex="1"> i.e. 100000</td>
</tr><tr><td width="50%" background="../images/lightgreen.gif">
<div align="right">Content Value = <input type="hidden" value="0.6" border="0" name=contentpc></div></td>
<td width="50%" background="../images/darkgreen.gif">£ <INPUT size=10 name=contentval> i.e. 6000</td></tr><tr>
<td width="50%" background="../images/lightgreen.gif">
<div align="right"><input onclick=perc1() type=button value=Calculate><INPUT type=reset value=Reset></div>
</td><td width="50%" background="../images/darkgreen.gif"></td></tr><tr>
<td width="50%" background="../images/lightgreen.gif">
<div align="right">Total Annual Payments<br>(inclusive of 5% Insurance Premium)</div></td><td width="50%" background="../images/darkgreen.gif">£ <input maxlength=40 size=10 name=final></td></tr></table>
</td><td valign="top"><div align="right"></div></td></tr>
</table></FORM></td></tr><tr></tr></table><p></p>
Thanks for checking it for me.
James Middleton
Ive put this together, I just a begginers with all this javascript stuff. I need to cause the final figure to read out in £'s and pence, i.e. £35.50 and not £35.5. I think that I need to incorporate another 'MATH' command, but I'm not sure how to......any ideas?
(this bit goes into the head)
<SCRIPT language=JavaScript>
/*
James Middleton - calculator
*/
<!--
function perc1() {
/* get value of property */
propertypc = document.form1.propertypc.value/100;
propertyval = propertypc*document.form1.propertyval.value
/* get value of contents */
contentpc = document.form1.contentpc.value/100;
contentval = contentpc*document.form1.contentval.value;
bothval = propertyval + contentval
premium = bothval / 100 * 5 + bothval
premium = Math.round(premium);
document.form1.final.value = "£" + premium
}
//-->
</script>
(This bit goes into the body)
<table width="400" border="0" cellspacing="0" cellpadding="10" height="250"><tr>
<td colspan="2" background="../images/darkgreen.gif">
<div align="right"><B><span class="Heading">Insurance Calculator</span></B></div></td></tr><tr>
<td width="50%" background="../images/lightgreen.gif">
<div align="right">Property Value = <input type="hidden" value="0.18" border="0" name=propertypc></div></td>
<td width="50%" background="../images/darkgreen.gif">£ <INPUT size=10 name=propertyval tabindex="1"> i.e. 100000</td>
</tr><tr><td width="50%" background="../images/lightgreen.gif">
<div align="right">Content Value = <input type="hidden" value="0.6" border="0" name=contentpc></div></td>
<td width="50%" background="../images/darkgreen.gif">£ <INPUT size=10 name=contentval> i.e. 6000</td></tr><tr>
<td width="50%" background="../images/lightgreen.gif">
<div align="right"><input onclick=perc1() type=button value=Calculate><INPUT type=reset value=Reset></div>
</td><td width="50%" background="../images/darkgreen.gif"></td></tr><tr>
<td width="50%" background="../images/lightgreen.gif">
<div align="right">Total Annual Payments<br>(inclusive of 5% Insurance Premium)</div></td><td width="50%" background="../images/darkgreen.gif">£ <input maxlength=40 size=10 name=final></td></tr></table>
</td><td valign="top"><div align="right"></div></td></tr>
</table></FORM></td></tr><tr></tr></table><p></p>
Thanks for checking it for me.
James Middleton