<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>The JavaScript Source: Forms : Update Order Form w/o Page Refresh</TITLE>
<META HTTP-EQUIV="The JavaScript Source" CONTENT = "no-cache">
<META NAME="description" CONTENT="In this order form, the cost for each item is totaled as the items are selected and deselected. This is done without refreshing the entire page in order to save other form information. Heavily commented.">
<META NAME="date" CONTENT="2005-12-21">
<META NAME="channel" CONTENT="Developer">
<META NAME="author" CONTENT="Kevin Hartig">
<META NAME="section" CONTENT="Forms">
<script type="text/javascript">
<!--
/* This script and many more are available free online at
The JavaScript Source :: [URL unfurl="true"]http://javascript.internet.com[/URL]
Created by: Kevin Hartig :: [URL unfurl="true"]http://www.grafikfx.net/[/URL] */
function calculateTotal() {
var total=0;
var el = document.forms['selectionForm'].elements;
for (x=0;x<el.length;x++) {
if (el[x].checked)
total+=el[x].value-0;
}
document.selectionForm.total.value = formatCurrency((total > 0)?total:0);
}
// Format a value as currency.
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
// This function initialzes all the form elements to default values.
function InitForm() {
// Reset values on form.
document.selectionForm.total.value='$0';
document.selectionForm.calculatedTotal.value=0;
document.selectionForm.previouslySelectedRadioButton.value=0;
// Set all checkboxes and radio buttons on form to unchecked.
for (i=0; i < document.selectionForm.elements.length; i++) {
if (document.selectionForm.elements[i].type == 'checkbox' | document.selectionForm.elements[i].type == 'radio') {
document.selectionForm.elements[i].checked = false;
}
}
}
//-->
</script>
</HEAD>
<BODY BGCOLOR=#ffffff vlink=#0000ff onLoad="InitForm();" onreset="InitForm();">
<BR>
<center>
<script language="JavaScript" type="text/javascript"><!--
function openDescription(ID) {
var url = "[URL unfurl="true"]http://www.ppcforhosts.com/public/util/description.cfm?id="[/URL] + ID;
link = window.open(url,"newWin","directories=0,height=250,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,width=450");
}
//--></script>
<div align="center">
<table width="600"><tr><td>
<form method="POST" name="selectionForm">
<p><b>How many Sessions will the camper be attending?</b> <br>
<input type="radio" name="Session" value="650.00" onClick="calculateTotal();">
1 Session $650.00 <br>
<input type="radio" name="Session" value="1300.00" onClick="calculateTotal();">
2 Sessions $1,300.00 <br>
<input type="radio" name="Session" value="1950.00" onClick="calculateTotal();">
3 Sessions $1,950.00 <br>
<input type="radio" name="Session" value="2600.00" onClick="calculateTotal();">
4 Sessions $2,600.00 <br>
<input type="radio" name="Session" value="3250.00" onClick="calculateTotal();">
5 Sessions $3,250.00</p>
<p> <br>
<b>Fee for supervising campers that are staying at camp between Sessions. Please specify how many weekends the campers is expected to stay at camp: </b> <br>
<input type="radio" name="Supervision" value="75.00" onClick="calculateTotal();">
1 Weekend $75.00 <br>
<input type="radio" name="Supervision" value="150.00" onClick="calculateTotal();">
2 Sessions $150.00 <br>
<input type="radio" name="Supervision" value="225.00" onClick="calculateTotal();">
3 Sessions $225.00 <br>
<input type="radio" name="Supervision" value="300.00" onClick="calculateTotal();">
4 Sessions $300.00 <br>
<input type="radio" name="Supervision" value="375.00" onClick="calculateTotal();">
5 Sessions $375.00 </p>
<p><br>
<b>Discounts</b><br>
<input type="checkbox" name="Discount_one" value="-50.00" onclick="calculateTotal();">$50.00 Discount
<input type="checkbox" name="Discount_two" value="-20.00" onClick="calculateTotal();">$20.00 Discount
<br>
<br>
<input type="hidden" name="calculatedTotal" value="0">
<input type="hidden" name="previouslySelectedRadioButton" value="0">
<strong>Your total is:</strong>
<input type="text" name="total" readonly onFocus="this.blur();">
</p>
</form>
</td></tr></table>
</div>
</center>
</body></html>