Menu
So I want to add a little dynamic touch to my order form. First of all, I don’t program in javascript, but I can take a script and modify it to my needs. The form I have basically has all numeric values used for calculation a grand total price.
Here is an example: [url]http://www.xibitony.net/order.php
Play around with it, but what I basically want to do is eliminate the “Calculate Cost” button. Could someone write up a quick little example as to how to accomplish this? Thanks!
<i>
</i><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Example</title>
<script type="text/javascript">
var prices = new Array('10','15','20','25','30','35','40','45','50','55','60');
var privOrPub = new Array('1','2');
var term = new Array('1','0.9','0.85','0.8');
<i> </i>function calculate(f){
<i> </i> var gamePrice = prices[f.game.value];
<i> </i> var servType = privOrPub[f.type.value];
<i> </i> var numOfPlayers = f.slots.value;
<i> </i> var discount = term[f.term.value];
<i> </i> alert(gamePrice);
<i> </i> alert(servType);
<i> </i> alert(numOfPlayers);
<i> </i> alert(discount);
<i> </i> var total = Number(gamePrice) * Number(servType) * Number(numOfPlayers) * Number(discount);
<i> </i> alert('Total is:' + total);
<i> </i>}
</script>
</head>
<body>
<form name="frmCalulate" action="" method="post">
<table cellSpacing="0" cellPadding="0" border="0">
<tr>
<td width="10"></td>
<td><b>Game</b><br>
Servers Available</td>
<td width="25"></td>
<td><select name="game" onchange="calculate(this.form);">
<option value="0" selected>America's Army</option>
<option value="1">Battlefield 1942</option>
<option value="2">Battlefield Vietnam</option>
<option value="3">Call of Duty</option>
<option value="4">Half-Life</option><option value='hlcs'>Half-Life: Counter-Strike</option>
<option value="5">Half-Life: Counter-Strike: Condition Zero</option>
<option value="6">Half-Life: Day of Defeat</option>
<option value="7">Half-Life: Team Fortress Classic</option>
<option value="8">Medal of Honor Allied Assault</option>
<option value="9">Raven Shield</option>
<option value="10">Raven Shield: Athena Sword</option>
</select>
</td>
<td width="10"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td height="10"></td>
<td width="25" height="10"></td>
<td height="10"></td>
<td width="10" height="10"></td>
</tr>
<tr>
<td width="10"></td>
<td><b>Type</b><br>
Public or Private</td>
<td width="25"></td>
<td><select name="type" onchange="calculate(this.form)">
<option value="0" selected>Public</option>
<option value="1">Private</option>
</select></td>
<td width="10"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td height="10"></td>
<td width="25" height="10"></td>
<td height="10"></td>
<td width="10" height="10"></td>
</tr>
<tr>
<td width="10"></td>
<td><b>Slots</b><br>
Maximum Players</td>
<td width="25"></td>
<td><input type="textbox" name="slots" size="3" value="10" onchange="if(this.value>=10 && this.value%2 == 0){calculate(this.form)}else{alert('Num mus be more than 10 or an even number');this.value='10';}"></td>
<td width="10"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td height="10"></td>
<td width="25" height="10"></td>
<td height="10"></td>
<td width="10" height="10"></td>
</tr>
<tr>
<td width="10"></td>
<td><b>Term</b><br>
Billing Cycle</td>
<td width="25"></td>
<td><select name="term" onchange="calculate(this.form)">
<option value="0" selected>Monthly</option>
<option value="1">Quarterly (10% Discount)</option>
<option value="2">Biannually (15% Discount)</option>
<option value="3">Yearly (20% Discount)</option>
</select></td>
<td width="10"></td>
</tr>
</table>
</form>
</body>
</html>
f.[color=red]<textboxnamehere>[/color].value = total
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Example</title>
<script type="text/javascript">
var prices = new Array('10','15','20','25','30','35','40','45','50','55','60','65');
var privOrPub = new Array('1','2');
var term = new Array('1','0.9','0.85','0.8');
<i> </i>var minimum = new Array('10','12','14','12','12','14','16','12','10','12','10','14');
<i> </i>var max = new Array('32','26','30','28','34','28','30','30','30','24','22','28');
<i> </i>function calculate(f){
<i> </i> var gamePrice = prices[f.game.value];
<i> </i> var servType = privOrPub[f.type.value];
<i> </i> var numOfPlayers = f.player.options[f.player.selectedIndex];
<i> </i> var discount = term[f.term.value];
<i> </i> var total = Number(gamePrice) * Number(servType) * Number(numOfPlayers) * Number(discount);
<i> </i> f.grandTotal.value = total;
<i> </i>}
<i> </i>function changeMaxMin(frm){
<i> </i> var index = frm.game.value;
<i> </i> var minVal = Number(minimum[index]);
<i> </i> var maxVal = Number(max[index]);
<i> </i> for(var j=0; j<frm.player.options.length; j++){
<i> </i> frm.player.options[j] = null;
<i> </i> }
<i> </i> var count = 0;
<i> </i> for(var i=minVal; i<=maxVal; i+=2){
<i> </i> frm.player.options[count] = new Option(i);
<i> </i> count++;
<i> </i> }
<i> </i>}
<i> </i>onload = function() {
<i> </i> changeMaxMin(document.frmCalculate);
<i> </i>}
</script>
</head>
<body>
<form name="frmCalculate" action="" method="post">
<table cellSpacing="0" cellPadding="0" border="0">
<tr>
<td width="10"></td>
<td><b>Game</b><br>
Servers Available</td>
<td width="25"></td>
<td><select name="game" onchange="changeMaxMin(this.form,this);calculate(this.form);">
<option value="0" selected>America's Army</option>
<option value="1">Battlefield 1942</option>
<option value="2">Battlefield Vietnam</option>
<option value="3">Call of Duty</option>
<option value="4">Half-Life</option>
<option value='5'>Half-Life: Counter-Strike</option>
<option value="6">Half-Life: Counter-Strike: Condition Zero</option>
<option value="7">Half-Life: Day of Defeat</option>
<option value="8">Half-Life: Team Fortress Classic</option>
<option value="9">Medal of Honor Allied Assault</option>
<option value="10">Raven Shield</option>
<option value="11">Raven Shield: Athena Sword</option>
</select>
</td>
<td width="10"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td height="10"></td>
<td width="25" height="10"></td>
<td height="10"></td>
<td width="10" height="10"></td>
</tr>
<tr>
<td width="10"></td>
<td><b>Type</b><br>
Public or Private</td>
<td width="25"></td>
<td><select name="type" onchange="calculate(this.form)">
<option value="0" selected>Public</option>
<option value="1">Private</option>
</select></td>
<td width="10"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td height="10"><b>players</b></td>
<td width="25" height="10"></td>
<td height="10"><select name="player" onchange="calculate(this.form)"></select></td>
<td width="10" height="10"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td height="10"></td>
<td width="25" height="10"></td>
<td height="10"></td>
<td width="10" height="10"></td>
</tr>
<tr>
<td width="10"></td>
<td><b>Term</b><br>
Billing Cycle</td>
<td width="25"></td>
<td><select name="term" onchange="calculate(this.form)">
<option value="0" selected>Monthly</option>
<option value="1">Quarterly (10% Discount)</option>
<option value="2">Biannually (15% Discount)</option>
<option value="3">Yearly (20% Discount)</option>
</select></td>
<td width="10"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><input type="text" name="grandTotal" readonly></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Example</title>
<script type="text/javascript">
var pubprices = new Array();
pubprices[1]="6.00";
pubprices[2]="5.50";
<i> </i>var privprices = new Array();
<i> </i> privprices[1]="4.00";
<i> </i> privprices[2]="3.50";
<i> </i>var minimum = new Array();
<i> </i> minimum[1]="8";
<i> </i> minimum[2]="10";
<i> </i>var maximum = new Array();
<i> </i> maximum[1]="64";
<i> </i> maximum[2]="32";
<i> </i>var term = new Array();
<i> </i> term[1]="0";
<i> </i> term[3]="0.1";
<i> </i> term[6]="0.15";
<i> </i> term[12]="0.2";
<i> </i>function calculate(f){
<i> </i> f.slots.value=Math.round(f.slots.value);
<i> </i> if(f.type.value==0){
<i> </i> var sub = pubprices[f.game.value] * f.slots.value * f.term.value;
<i> </i> }else{
<i> </i> var sub = privprices[f.game.value] * f.slots.value * f.term.value;
<i> </i> }
<i> </i> var discount = sub * term[f.term.value];
<i> </i> var total = sub - discount;
<i> </i> f.gentotal.value = "$"+total.toFixed(2);
<i> </i>}
<i> </i>function changeMaxMin(frm){
<i> </i> var index = frm.game.value;
<i> </i> var minVal = Number(minimum[index]);
<i> </i> var maxVal = Number(maximum[index]);
<i> </i> for(var j=0; j<frm.slots.options.length; j++){
<i> </i> frm.slots.options[j] = null;
<i> </i> }
<i> </i> var count = 0;
<i> </i> for(var i=minVal; i<=maxVal; i+=2){
<i> </i> frm.slots.options[count] = new Option(i);
<i> </i> count++;
<i> </i> }
<i> </i>}
<i> </i>onload = function() {
<i> </i> changeMaxMin(document.serverform);
<i> </i>}
</script>
</head>
<body onload="calculate(serverform)">
<form name="serverform" action="" method="post">
<table cellSpacing="0" cellPadding="0" border="0">
<tr>
<td width="10"></td>
<td><b>Game</b><br>
Servers Available</td>
<td width="25"></td>
<td><select name="game" onchange="changeMaxMin(this.form,this);calculate(this.form);">
<option value="2">Battlefield 1942</option>
<option value="1">Battlefield Vietnam</option>
</select> </td>
<td width="10"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td height="10"></td>
<td width="25" height="10"></td>
<td height="10"></td>
<td width="10" height="10"></td>
</tr>
<tr>
<td width="10"></td>
<td><b>Type</b><br>
Public or Private</td>
<td width="25"></td>
<td><select name="type" onchange="calculate(this.form)">
<option value="0" selected>Public</option>
<option value="1">Private</option>
</select></td>
<td width="10"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td height="10"></td>
<td width="25" height="10"></td>
<td height="10"></td>
<td width="10" height="10"></td>
</tr>
<tr>
<td width="10"></td>
<td><b>Slots</b><br>
Maximum Players</td>
<td width="25"></td>
<td>
<select name="slots" onchange="calculate(this.form)"></select></td>
<td width="10"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td height="10"></td>
<td width="25" height="10"></td>
<td height="10"></td>
<td width="10" height="10"></td>
</tr>
<tr>
<td width="10"></td>
<td><b>Term</b><br>
Billing Cycle</td>
<td width="25"></td>
<td><select name="term" onchange="calculate(this.form)">
<option value="1" selected>Monthly</option>
<option value="3">Quarterly (10% Discount)</option>
<option value="6">Biannually (15% Discount)</option>
<option value="12">Yearly (20% Discount)</option>
</select></td>
<td width="10"></td>
</tr>
<tr>
<td width="10" height="10"></td>
<td height="10"></td>
<td width="25" height="10"></td>
<td height="10"></td>
<td width="10" height="10"></td>
</tr>
<tr>
<td width="10"></td>
<td><b>Cost</b><br>
Per Term</td>
<td width="25"></td>
<td><input type="text" name="gentotal" size="10" style="cursor: default" readonly></td>
<td width="10"></td>
</tr>
</table>
</form>
</body>
</html>
<i>
</i>select name="game" onchange="changeMaxMin(this.form,this)"
<i>
</i>function changeMaxMin(frm){
var index = frm.game.value;
var minVal = Number(minimum[index]);
var maxVal = Number(maximum[index]);
<i> </i>for(var j=0; j<frm.slots.options.length; j++){
<i> </i> frm.slots.options[j] = null;
<i> </i>}
<i> </i>var count = 0;
<i> </i>for(var i=minVal; i<=maxVal; i+=2){
<i> </i> frm.slots.options[count] = new Option(i);
<i> </i> count++;
<i> </i>}
}
<i>
</i>for(var j=0; j<frm.slots.options.length; j++){
frm.slots.options[j] = null;
}
<i>
</i>document.forms['serverform'].slots.options.length = 0;
Switch the game to Raven Shield. In the JavaScript it calls for all even numbers between 8 and 16, but it shows an extra 32 in there...i don't see an extra 32..
[/quote]
<i>
</i> <tr>
<td height="10"></td>
<td width="25" height="10"></td>
<td height="10"></td>
</tr>
<span id="hlopt"></span>
<tr>
<td><b>Location</b><br>
Data Center</td>
<td width="25"></td>
<td><select name="location">
<option selected>Dallas, TX</option>
<option>Chicago, IL</option>
<option>Richmond, VA</option>
<option>San Jose, CA</option>
</select></td>
</tr>
<i>
</i> function extraOptions(fm){
if(fm.game.value==3||fm.game.value==4||fm.game.value==5||fm.game.value==6||fm.game.value==7){
document.getElementById('hlopt').innerHTML = "<tr><td><b>HLTV</b><br>Settings</td><td width='25'></td><td><select name='hl_hltv'><option value='1'>On</option><option value='0'>Off</option></select></td></tr><tr><td height='10'></td><td width='25' height='10'></td><td height='10'></td></tr>";
}else{
document.getElementById('hlopt').innerHTML = "";
}
}
0.1.9 — BETA 5.5