Joerubes
01-13-2007, 04:09 PM
I am trying to set up a booking form for a conference.
The organisers want to offer discount where for every 5 places booked the sixth one is free.
I have tried to write the script that will calculate the total taking this discount into account. It works when I write if(el.value >= 6) total = (el.value * 40) -40; for the first if statement
but when I change it to if(el.value >= 6 and el.value <=11) total = (el.value * 40) -40;
the form stops working.
I am aware I need to add further 'else if' statements for bigger group bookings but I would first like to get this basic one working.
I am sure there is a 'prettier' mathematical formula for doing this calculation which if anyone can helpwith I would much appreciate it!
Here is my complete script so far...
<script language="javascript" type="text/javascript">
function updateCost() {
var total = 0;
var cf = "totalCost";
var el = document.getElementById('delegates');
if(el.value >= 6 and el.value <=11) total = (el.value * 40) -40; else total = el.value * 40;
document.getElementById('totaloutput').innerHTML = "£" + total;
document.getElementById('totalprice').value = total;
}
</script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p> </p>
<p> </p>
<form method="post" action="https://www....">
<input type="hidden" name="redirect" value="http://www..../thanks.htm" />
<input type="hidden" name="totalprice" id="totalprice" value="0" />
<table width="60%" border="0" align="center" cellpadding="5" cellspacing="0">
<tr bgcolor="#ECD399">
<td width="672"><span class="style3"><strong>Total Number of conference places </strong></span></td>
<td width="250" colspan="2"><input type="text" name="delegates" id="delegates" value="0" onchange="updateCost();" />
</tr>
<tr bgcolor="#ECD399">
<td><span class="style3">Total cost:</span></td>
<td id="totaloutput">£0.00 </td>
<td id="totaloutput"><input type="button" name="Button" value="Calculate" /></td>
</tr>
<tr bgcolor="#ECD399">
<td colspan="3"><input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Reset" value="Reset" /></td>
</tr>
</table>
</form>
The organisers want to offer discount where for every 5 places booked the sixth one is free.
I have tried to write the script that will calculate the total taking this discount into account. It works when I write if(el.value >= 6) total = (el.value * 40) -40; for the first if statement
but when I change it to if(el.value >= 6 and el.value <=11) total = (el.value * 40) -40;
the form stops working.
I am aware I need to add further 'else if' statements for bigger group bookings but I would first like to get this basic one working.
I am sure there is a 'prettier' mathematical formula for doing this calculation which if anyone can helpwith I would much appreciate it!
Here is my complete script so far...
<script language="javascript" type="text/javascript">
function updateCost() {
var total = 0;
var cf = "totalCost";
var el = document.getElementById('delegates');
if(el.value >= 6 and el.value <=11) total = (el.value * 40) -40; else total = el.value * 40;
document.getElementById('totaloutput').innerHTML = "£" + total;
document.getElementById('totalprice').value = total;
}
</script>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p> </p>
<p> </p>
<form method="post" action="https://www....">
<input type="hidden" name="redirect" value="http://www..../thanks.htm" />
<input type="hidden" name="totalprice" id="totalprice" value="0" />
<table width="60%" border="0" align="center" cellpadding="5" cellspacing="0">
<tr bgcolor="#ECD399">
<td width="672"><span class="style3"><strong>Total Number of conference places </strong></span></td>
<td width="250" colspan="2"><input type="text" name="delegates" id="delegates" value="0" onchange="updateCost();" />
</tr>
<tr bgcolor="#ECD399">
<td><span class="style3">Total cost:</span></td>
<td id="totaloutput">£0.00 </td>
<td id="totaloutput"><input type="button" name="Button" value="Calculate" /></td>
</tr>
<tr bgcolor="#ECD399">
<td colspan="3"><input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Reset" value="Reset" /></td>
</tr>
</table>
</form>