Script Categories













Forms >>> 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.

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:

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- 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) {
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>
<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>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).

Bitcoin Gambling Site . link


©