Forum Moderators: open
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Calculator</title>
<script type="text/javascript">
function Calc() {
var numDays = Math.round(eval(document.myform.days.value))
var taxPercent = 0.122
var tempRate = 0
if (numDays<4)
{
tempRate = 250
}
else if (numDays<7)
{
tempRate = 230
}
else if (numDays<30)
{
tempRate = 200
}
else
{
tempRate = 150
}
var tempSub = numDays * tempRate
var tempTax = tempSub * taxPercent
var tempTotal = tempSub + tempTax
document.myform.rate.value=formatNumber(tempRate, 2, ',', '.', '$', ' USD')
document.myform.subtotal.value=formatNumber(tempSub, 2, ',', '.', '$', ' USD')
document.myform.tax.value=formatNumber(tempTax, 2, ',', '.', '$', ' USD')
document.myform.amount.value=formatNumber(tempTotal, 2, ',', '.', '$', ' USD');
}
// number formatting function
// copyright Stephen Chapman 24th March 2006, 22nd August 2008
// permission to use this function is granted provided
// that this copyright notice is retained intact
function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2)
{
var x = Math.round(num * Math.pow(10,dec));
if (x >= 0) n1=n2='';
var y = (''+Math.abs(x)).split('');
var z = y.length - dec;
if (z<0) z--;
for(var i = z; i < 0; i++) y.unshift('0');
if (z<0) z = 1;
y.splice(z, 0, pnt);
if(y[0] == pnt) y.unshift('0');
while (z > 3)
{
z-=3; y.splice(z,0,thou);
}
var r = curr1+n1+y.join('')+n2+curr2;
return r;
}
</script>
</head>
<center>
<form name="myform" action="none">
<table border="5">
<tr>
<td>Number of Nights:</td>
<td>
<input type="text" name="days">
</td>
</tr>
<tr>
<td>Daily rate:</td>
<td>
<input type="text" name="rate" readonly>
</td>
</tr>
<tr>
<td>Subtotal:</td>
<td>
<input type="text" name="subtotal" readonly>
</td>
</tr>
<tr>
<td>Sales tax:</td>
<td>
<input type="text" name="tax" readonly>
</td>
</tr>
<tr>
<td>Total including tax:</td>
<td>
<input type="text" name="amount" readonly>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="button" value="Calculate" onClick="Calc()" name="button">
</td>
</tr>
</table>
</form>
</center> [edited by: tedster at 5:18 am (utc) on Mar 30, 2010]
[edit reason] Sorry, no personal links [/edit]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Bryce Vacation House Rate Calculator</title>
<script type="text/javascript">
function Calc() {
var numDays = Math.round(eval(document.myform.days.value))
var taxPercent = 0.122
var tempRate = 0
if (numDays<4)
{
tempRate = 250
}
else if (numDays<7)
{
tempRate = 230
}
else if (numDays<30)
{
tempRate = 200
}
else
{
tempRate = 150
}
var tempSub = numDays * tempRate
var tempTax = tempSub * taxPercent
var tempTotal = tempSub + tempTax
document.myform.rate.value=formatNumber(tempRate, 2, ',', '.', '$', ' USD')
document.myform.subtotal.value=formatNumber(tempSub, 2, ',', '.', '$', ' USD')
document.myform.tax.value=formatNumber(tempTax, 2, ',', '.', '$', ' USD')
document.myform.amount.value=formatNumber(tempTotal, 2, ',', '.', '$', ' USD');
}
// number formatting function
// copyright Stephen Chapman 24th March 2006, 22nd August 2008
// permission to use this function is granted provided
// that this copyright notice is retained intact
function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2)
{
var x = Math.round(num * Math.pow(10,dec));
if (x >= 0) n1=n2='';
var y = (''+Math.abs(x)).split('');
var z = y.length - dec;
if (z<0) z--;
for(var i = z; i < 0; i++) y.unshift('0');
if (z<0) z = 1;
y.splice(z, 0, pnt);
if(y[0] == pnt) y.unshift('0');
while (z > 3)
{
z-=3; y.splice(z,0,thou);
}
var r = curr1+n1+y.join('')+n2+curr2;
return r;
}
</script>
</head>
<body>
<center>
<form name="myform" action="none">
<table border="5">
<tr>
<td>Number of Nights:</td>
<td>
<input type="text" name="days">
</td>
</tr>
<tr>
<td>Daily rate:</td>
<td>
<input type="text" name="rate" readonly>
</td>
</tr>
<tr>
<td>Subtotal:</td>
<td>
<input type="text" name="subtotal" readonly>
</td>
</tr>
<tr>
<td>Sales tax:</td>
<td>
<input type="text" name="tax" readonly>
</td>
</tr>
<tr>
<td>Total including tax:</td>
<td>
<input type="text" name="amount" readonly>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="button" value="Calculate" onClick="Calc()" name="button">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Bryce Vacation House Rate Calculator</title>
<script type="text/javascript">
// Note "form" is the reference to the object, no need to refer to it by name.
// Return false is what stops it from submittting.
function Calc(form) {
var numDays = Math.round(eval(form.days.value));
var taxPercent = 0.122;
var tempRate = 0;
// error handler
if (! (numDays > 0)) { alert('Enter number of days.'); return false; }
if (numDays<4) { tempRate = 250; }
else if (numDays<7) { tempRate = 230; }
else if (numDays<30) { tempRate = 200; }
else { tempRate = 150; }
var tempSub = numDays * tempRate;
var tempTax = tempSub * taxPercent;
var tempTotal = tempSub + tempTax;
form.rate.value=formatNumber(tempRate, 2, ',', '.', '$', ' USD')
form.subtotal.value=formatNumber(tempSub, 2, ',', '.', '$', ' USD')
form.tax.value=formatNumber(tempTax, 2, ',', '.', '$', ' USD')
form.amount.value=formatNumber(tempTotal, 2, ',', '.', '$', ' USD');
return false;
}
//
function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {
var x = Math.round(num * Math.pow(10,dec));
if (x >= 0) { n1=n2=''; }
var y = (''+Math.abs(x)).split('');
var z = y.length - dec;
if (z<0) { z--; }
for(var i = z; i < 0; i++) { y.unshift('0'); }
if (z<0) { z = 1; }
y.splice(z, 0, pnt);
if(y[0] == pnt) { y.unshift('0'); }
while (z > 3) {
z-=3; y.splice(z,0,thou);
}
var r = curr1+n1+y.join('')+n2+curr2;
return r;
}
</script>
</head>
<body>
<!-- not the onsubmit handler passes the form ref. via the 'this' keyword -->
<form name="myform" action="" onsubmit="return Calc(this);">
<table style="margin:auto"; border="5">
<tr><td>Number of Nights:</td><td><input type="text" name="days"></td></tr>
<tr><td>Daily rate:</td><td><input type="text" name="rate" readonly></td></tr>
<tr><td>Subtotal:</td><td><input type="text" name="subtotal" readonly></td></tr>
<tr><td>Sales tax:</td><td><input type="text" name="tax" readonly></td></tr>
<tr><td>Total including tax:</td><td><input type="text" name="amount" readonly></td></tr>
<tr><td> </td><td><input type="submit" value="Calculate" name="submitButton"></td></tr>
</table>
</form>
</body>
</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">
<head>
...
</head>
<form>
.
.
.
</iframe><script type="text/javascript">
setTimeout('HtmlControlJS.loadFrame\x28\x27ctl00_IWS_WH_CPH_Content_HtmlControl2\x27, \x27\x5cx3c\x5cx21DOCTYPE html PUBLIC \x5cx22-\x5cx2f\x5cx2fW3C\x5cx2f\x5cx2fDTD HTML 4.01 Transitional\x5cx2f\x5cx2fEN\x5cx22 \x5cx0d\x5cx0a\x5cx22http\x5cx3a\x5cx2f\x5cx2fwww.w3.org\x5cx2fTR\x5cx2fhtml4\x5cx2floose.dtd\x5cx22\x5cx3e \x5cx0d\x5cx0a\x5cx3chtml\x5cx3e \x5cx0d\x5cx0a\x5cx3chead\x5cx3e \x5cx0d\x5cx0a\x5cx3cmeta http-equiv\x5cx3d\x5cx22Content-type\x5cx22 content\x5cx3d\x5cx22text\x5cx2fhtml\x5cx3bcharset\x5cx3dUTF-8\x5cx22\x5cx3e \x5cx0d\x5cx0a\x5cx3ctitle\x5cx3eBryce Vacation House Rate Calculator\x5cx3c\x5cx2ftitle\x5cx3e \x5cx0d\x5cx0a\x5cx3cscript type\x5cx3d\x5cx22text\x5cx2fjavascript\x5cx22\x5cx3e \x5cx0d\x5cx0a\x5cx2f\x5cx2f Note \x5cx22form\x5cx22 is the reference to the object, no need to refer to it by name. \x5cx0d\x5cx0a\x5cx2f\x5cx2f Return false is what stops it from submittting. \x5cx0d\x5cx0afunction Calc\x5cx28form\x5cx29 \x5cx7b \x5cx0d\x5cx0a var numNights \x5cx3d Math.round\x5cx28eval\x5cx28form.days.value\x5cx29\x5cx29\x5cx3b \x5cx0d\x5cx0a var taxPercent \x5cx3d 0.122\x5cx3b \x5cx0d\x5cx0a var temprate \x5cx3d 0\x5cx3b \x5cx0d\x5cx0a \x5cx2f\x5cx2f error handler \x5cx0d\x5cx0a if \x5cx28\x5cx21 \x5cx28numNights \x5cx3e 0\x5cx29\x5cx29 \x5cx7b alert\x5cx28\x5cx27Please enter number of nights.\x5cx27\x5cx29\x5cx3b return false\x5cx3b \x5cx7d \x5cx0d\x5cx0a if \x5cx28numNights\x5cx3c4\x5cx29 \x5cx7b temprate \x5cx3d 250\x5cx3b \x5cx7d \x5cx0d\x5cx0a else if \x5cx28numNights\x5cx3c7\x5cx29 \x5cx7b temprate \x5cx3d 230\x5cx3b \x5cx7d \x5cx0d\x5cx0a else if \x5cx28numNights\x5cx3c30\x5cx29 \x5cx7b temprate \x5cx3d 200\x5cx3b \x5cx7d \x5cx0d\x5cx0a else \x5cx7b temprate \x5cx3d 150\x5cx3b \x5cx7d \x5cx0d\x5cx0a var tempSub \x5cx3d numNights \x5cx2a temprate\x5cx3b \x5cx0d\x5cx0a var temptax \x5cx3d tempSub \x5cx2a taxPercent\x5cx3b \x5cx0d\x5cx0a var tempTotal \x5cx3d tempSub \x5cx2b temptax\x5cx3b \x5cx0d\x5cx0a form.rate.value\x5cx3dformatNumber\x5cx28temprate, 2, \x5cx27,\x5cx27, \x5cx27.\x5cx27, \x5cx27\x5cx24\x5cx27, \x5cx27 USD\x5cx27\x5cx29 \x5cx0d\x5cx0a form.subtotal.value\x5cx3dformatNumber\x5cx28tempSub, 2, \x5cx27,\x5cx27, \x5cx27.\x5cx27, \x5cx27\x5cx24\x5cx27, \x5cx27 USD\x5cx27\x5cx29 \x5cx0d\x5cx0a form.tax.value\x5cx3dformatNumber\x5cx28temptax, 2, \x5cx27,\x5cx27, \x5cx27.\x5cx27, \x5cx27\x5cx24\x5cx27, \x5cx27 USD\x5cx27\x5cx29 \x5cx0d\x5cx0a form.amount.value\x5cx3dformatNumber\x5cx28tempTotal, 2, \x5cx27,\x5cx27, \x5cx27.\x5cx27, \x5cx27\x5cx24\x5cx27, \x5cx27 USD\x5cx27\x5cx29\x5cx3b \x5cx0d\x5cx0a return false\x5cx3b \x5cx0d\x5cx0a\x5cx7d \x5cx0d\x5cx0a\x5cx2f\x5cx2f number formatting function\x5cx0d\x5cx0a\x5cx2f\x5cx2f copyright Stephen Chapman 24th March 2006, 22nd August 2008\x5cx0d\x5cx0a\x5cx2f\x5cx2f permission to use this function is granted provided\x5cx0d\x5cx0a\x5cx2f\x5cx2f that this copyright notice is retained intact\x5cx0d\x5cx0afunction formatNumber\x5cx28num,dec,thou,pnt,curr1,curr2,n1,n2\x5cx29 \x5cx7b \x5cx0d\x5cx0a var x \x5cx3d Math.round\x5cx28num \x5cx2a Math.pow\x5cx2810,dec\x5cx29\x5cx29\x5cx3b \x5cx0d\x5cx0a if \x5cx28x \x5cx3e\x5cx3d 0\x5cx29 \x5cx7b n1\x5cx3dn2\x5cx3d\x5cx27\x5cx27\x5cx3b \x5cx7d \x5cx0d\x5cx0a var y \x5cx3d \x5cx28\x5cx27\x5cx27\x5cx2bMath.abs\x5cx28x\x5cx29\x5cx29.split\x5cx28\x5cx27\x5cx27\x5cx29\x5cx3b \x5cx0d\x5cx0a var z \x5cx3d y.length - dec\x5cx3b \x5cx0d\x5cx0a if \x5cx28z\x5cx3c0\x5cx29 \x5cx7b z--\x5cx3b \x5cx7d \x5cx0d\x5cx0a for\x5cx28var i \x5cx3d z\x5cx3b i \x5cx3c 0\x5cx3b i\x5cx2b\x5cx2b\x5cx29 \x5cx7b y.unshift\x5cx28\x5cx270\x5cx27\x5cx29\x5cx3b \x5cx7d \x5cx0d\x5cx0a if \x5cx28z\x5cx3c0\x5cx29 \x5cx7b z \x5cx3d 1\x5cx3b \x5cx7d \x5cx0d\x5cx0a y.splice\x5cx28z, 0, pnt\x5cx29\x5cx3b \x5cx0d\x5cx0a if\x5cx28y\x5cx5b0\x5cx5d \x5cx3d\x5cx3d pnt\x5cx29 \x5cx7b y.unshift\x5cx28\x5cx270\x5cx27\x5cx29\x5cx3b \x5cx7d \x5cx0d\x5cx0a while \x5cx28z \x5cx3e 3\x5cx29 \x5cx7b \x5cx0d\x5cx0a z-\x5cx3d3\x5cx3b y.splice\x5cx28z,0,thou\x5cx29\x5cx3b \x5cx0d\x5cx0a \x5cx7d \x5cx0d\x5cx0a var r \x5cx3d curr1\x5cx2bn1\x5cx2by.join\x5cx28\x5cx27\x5cx27\x5cx29\x5cx2bn2\x5cx2bcurr2\x5cx3b \x5cx0d\x5cx0a return r\x5cx3b \x5cx0d\x5cx0a\x5cx7d \x5cx0d\x5cx0a\x5cx3c\x5cx2fscript\x5cx3e \x5cx0d\x5cx0a\x5cx3c\x5cx2fhead\x5cx3e \x5cx0d\x5cx0a\x5cx3cbody\x5cx3e \x5cx0d\x5cx0a\x5cx3c\x5cx21-- not the onsubmit handler passes the form ref. via the \x5cx27this\x5cx27 keyword --\x5cx3e \x5cx0d\x5cx0a\x5cx3cform name\x5cx3d\x5cx22myform\x5cx22 action\x5cx3d\x5cx22\x5cx22 onsubmit\x5cx3d\x5cx22return Calc\x5cx28this\x5cx29\x5cx3b\x5cx22 method\x5cx3d\x5cx22get\x5cx2fpost\x5cx22\x5cx3e \x5cx0d\x5cx0a \x5cx3ctable style\x5cx3d\x5cx22margin\x5cx3aauto\x5cx22 border\x5cx3d\x5cx225\x5cx22\x5cx3e \x5cx0d\x5cx0a \x5cx3ctr\x5cx3e\x5cx3ctd\x5cx3eNumber of Nights\x5cx3a\x5cx3c\x5cx2ftd\x5cx3e\x5cx3ctd\x5cx3e\x5cx3cinput type\x5cx3d\x5cx22text\x5cx22 name\x5cx3d\x5cx22days\x5cx22\x5cx3e\x5cx3c\x5cx2ftd\x5cx3e\x5cx3c\x5cx2ftr\x5cx3e \x5cx0d\x5cx0a \x5cx3ctr\x5cx3e\x5cx3ctd\x5cx3eDaily rate\x5cx3a\x5cx3c\x5cx2ftd\x5cx3e\x5cx3ctd\x5cx3e\x5cx3cinput type\x5cx3d\x5cx22text\x5cx22 name\x5cx3d\x5cx22rate\x5cx22 readonly\x5cx3e\x5cx3c\x5cx2ftd\x5cx3e\x5cx3c\x5cx2ftr\x5cx3e \x5cx0d\x5cx0a \x5cx3ctr\x5cx3e\x5cx3ctd\x5cx3eSubtotal\x5cx3a\x5cx3c\x5cx2ftd\x5cx3e\x5cx3ctd\x5cx3e\x5cx3cinput type\x5cx3d\x5cx22text\x5cx22 name\x5cx3d\x5cx22subtotal\x5cx22 readonly\x5cx3e\x5cx3c\x5cx2ftd\x5cx3e\x5cx3c\x5cx2ftr\x5cx3e \x5cx0d\x5cx0a \x5cx3ctr\x5cx3e\x5cx3ctd\x5cx3eSales tax\x5cx3a\x5cx3c\x5cx2ftd\x5cx3e\x5cx3ctd\x5cx3e\x5cx3cinput type\x5cx3d\x5cx22text\x5cx22 name\x5cx3d\x5cx22tax\x5cx22 readonly\x5cx3e\x5cx3c\x5cx2ftd\x5cx3e\x5cx3c\x5cx2ftr\x5cx3e \x5cx0d\x5cx0a \x5cx3ctr\x5cx3e\x5cx3ctd\x5cx3eTotal including tax\x5cx3a\x5cx3c\x5cx2ftd\x5cx3e\x5cx3ctd\x5cx3e\x5cx3cinput type\x5cx3d\x5cx22text\x5cx22 name\x5cx3d\x5cx22amount\x5cx22 readonly\x5cx3e\x5cx3c\x5cx2ftd\x5cx3e\x5cx3c\x5cx2ftr\x5cx3e \x5cx0d\x5cx0a \x5cx3ctr\x5cx3e\x5cx3ctd\x5cx3e\x5cx26nbsp\x5cx3b \x5cx3c\x5cx2ftd\x5cx3e\x5cx3ctd\x5cx3e\x5cx3cinput type\x5cx3d\x5cx22submit\x5cx22 value\x5cx3d\x5cx22Calculate\x5cx22 name\x5cx3d\x5cx22submitButton\x5cx22\x5cx3e\x5cx3c\x5cx2ftd\x5cx3e\x5cx3c\x5cx2ftr\x5cx3e \x5cx0d\x5cx0a \x5cx3c\x5cx2ftable\x5cx3e\x5cx0d\x5cx0a\x5cx3c\x5cx2fform\x5cx3e \x5cx0d\x5cx0a\x5cx3c\x5cx2fbody\x5cx3e \x5cx0d\x5cx0a\x5cx3c\x5cx2fhtml\x5cx3e \x27,1033, \x272.02.2715.0\x27\x29\x3b', 0);
.
.
.
</form>
.
.
.