form totals




JavaScript Source Code 3000: Forms: Form Totals















num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
cents = Math.floor((num*100+0.5)%100);
num = Math.floor((num*100+0.5)/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 ("$" + num + "." + cents);
}
// End -->

























Form Totals







Presents an order form with checkboxes and upates the total price as the user checks and unchecks boxes. The visitor also cannot change the total field. Currently only supports selecting one of each item. More JavaScript forms available at http://members.aol.com/irandd/.










Example 1
Steak $15.25
Chicken $12.39
Sushi $18.75

Your total is:






Example 2
Tea $ .50
Cola $ .79
Coffee $ 1.75

Your total is:











JavaScript Source Code 3000: Forms: Form Totals
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!





    





<!-- TWO STEPS TO INSTALL FORM TOTALS:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Paul Brino (irandd@aol.com) -->

<! >
<! >

<!-- Begin
function checkChoice(whichbox) {
with (whichbox.form) {
if (whichbox.checked == false)
hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value);
else
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value);
return(formatCurrency(hiddentotal.value));
}
}
function formatCurrency(num) {
<!-- Function courtesy of: Cyanide_7 (leo7278@hotmail.com) -->
<!-- Web Site: http://www7.ewebcity.com/cyanide7 -->
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
cents = Math.floor((num*100+0.5)%100);
num = Math.floor((num*100+0.5)/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 ("$" + num + "." + cents);
}
// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<center>
<table>
<tr>
<td>
<form name=myform>
<pre>
<b>Example 1</b>
Steak $15.25 <input type=checkbox name=Steak value="15.25" onClick="this.form.total.value=checkChoice(this);">
Chicken $12.39 <input type=checkbox name=Chicken value="12.39" onClick="this.form.total.value=checkChoice(this);">
Sushi $18.75 <input type=checkbox name=Sushi value="18.75" onClick="this.form.total.value=checkChoice(this);">
<br>
Your total is: <input type="text" name="total" value="" size=6 readonly><input type=hidden name=hiddentotal value=0>
</pre>
</form>

<hr width="100%" noshsde>
<form name=myform2>
<pre>
<b>Example 2</b>
Tea $ .50 <input type=checkbox name=Tea value=".50" onClick="this.form.total.value=checkChoice(this);">
Cola $ .79 <input type=checkbox name=Cola value=".79" onClick="this.form.total.value=checkChoice(this);">
Coffee $ 1.75 <input type=checkbox name=Coffee value="1.75" onClick="this.form.total.value=checkChoice(this);">
<br>
Your total is: <input type="text" name="total" value="" size=6 readonly><input type=hidden name=hiddentotal value=0>
</pre>
</form>

</td>
</tr>
</table>
</center>



<!-- Script Size: 2.56 KB -->











Wyszukiwarka

Podobne podstrony:
Normalizer Form
krs form wf
optymw form
form
Środki antyadhezyjne do uwalniania wyrobów z form
Redneck Application Form
form
second conditional form
10 RODZAJE FORM DRUKARSKICH
form

więcej podobnych podstron