<scriptlanguage="javascript"type="text/javascript"> /* Visit http://www.yaldex.com/
for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
//Define function to manipulate the form total per item
selected/deselected: function
CheckChoice(whichbox,
Price){ with(whichbox.form){ //Handle differently, depending
on type of input box. if(whichbox.type=="radio"){ //First, back out the prior
radio selection's price from the total: hiddentotal.value=eval(hiddentotal.value)-eval(hiddenpriorradio.value); //Then, save the current radio
selection's price: hiddenpriorradio.value=eval(Price); //Now, apply the current radio
selection's price to the total: hiddentotal.value=eval(hiddentotal.value)+eval(Price);
} else{ //If box was checked, accumulate
the checkbox value as the form total,
//Otherwise, reduce the form total by the checkbox value: if(whichbox.checked==false){ hiddentotal.value=eval(hiddentotal.value)-eval(whichbox.value);
} else{ hiddentotal.value=eval(hiddentotal.value)+eval(whichbox.value); }
} //Ensure the total never goes
negative (some browsers allow radiobutton to be deselected): if(hiddentotal.value<0){ InitForm();
} //Now, return with formatted
total: return(formatCurrency(hiddentotal.value)); }
} //Define function to format a
value as currency: 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);
} //Define function to init the
form on reload: function
InitForm(){ //Reset the displayed total on
form: document.myform.total.value='$0'; document.myform.hiddentotal.value=0; document.myform.hiddenpriorradio.value=0; document.myform2.total.value='$0'; document.myform2.hiddentotal.value=0; document.myform2.hiddenpriorradio.value=0; document.myform2.hiddenpriorradio.value=0; //Set all checkboxes and radio
buttons on form-1 to unchecked: for(xx=0;
xx <document.myform.elements.length;
xx++){ if(document.myform.elements[xx].type=='checkbox'|document.myform.elements[xx].type=='radio'){ document.myform.elements[xx].checked=false; }
} //Set all checkboxes and radio
buttons on form-2 to unchecked: for(xx=0;
xx <document.myform2.elements.length;
xx++){ if(document.myform2.elements[xx].type=='checkbox'|document.myform2.elements[xx].type=='radio'){ document.myform2.elements[xx].checked=false; } }
} // End --> </script> <formmethod=POSTname=myform> Steak $15.25 <inputtype=checkboxname=Steakvalue=15.25onClick="this.form.total.value=CheckChoice(this);"> Chicken $12.39 <inputtype=checkboxname=Chickenvalue=12.39onClick="this.form.total.value=CheckChoice(this);"> Sushi $18.75 <inputtype=checkboxname=Sushivalue=18.75onClick="this.form.total.value=CheckChoice(this);"> <br>
<br>
<b>Prepare
with this special sauce (extra charge -- only one selection allowed):</b>
<br> None, thanks <inputtype=radioname=Saucevalue=noneonClick="this.form.total.value=CheckChoice(this,
0.00);"> Duck Sauce $10.99 <inputtype=radioname=Saucevalue=duckonClick="this.form.total.value=CheckChoice(this,
10.99);"> Ginger Sauce $5.00 <inputtype=radioname=Saucevalue=gingeronClick="this.form.total.value=CheckChoice(this,
5.00);"> Hot Sauce $1.50 <inputtype=radioname=Saucevalue=hotonClick="this.form.total.value=CheckChoice(this,1.50);"> <br>
<br>
<br> <inputtype=hiddenname=hiddentotalvalue=0>
<input
type=hiddenname=hiddenpriorradiovalue=0> Your total is: <inputtype=textname=totalreadonly> <br>
<br> (Note: Total can not be changed by the
visitor.) </font> </form> <hrwidth=100%noshade> <formmethod=POSTname=myform2> Roasted Pig $10.00 <inputtype=checkboxname=Pigvalue=10.00onClick="this.form.total.value=CheckChoice(this);"> Roasted Rat $17.49 <inputtype=checkboxname=Ratvalue=17.49onClick="this.form.total.value=CheckChoice(this);"> Roasted Cat $3.50 <inputtype=checkboxname=Catvalue=3.50onClick="this.form.total.value=CheckChoice(this);"> <br>
<br>
<b>Prepare
with this special seasoning (extra charge -- only one selection
allowed):</b>
<br> None, thanks <inputtype=radioname=Seasonvalue=noneonClick="this.form.total.value=CheckChoice(this,0.00);"> Liquid Nitrogen $17.50 <inputtype=radioname=Seasonvalue=nitrogenonClick="this.form.total.value=CheckChoice(this,17.50);"> Gun Powder $8.50 <inputtype=radioname=Seasonvalue=gunpowderonClick="this.form.total.value=CheckChoice(this,
8.50);"> Vodka $4.00 <inputtype=radioname=Seasonvalue=vodkaonClick="this.form.total.value=CheckChoice(this,
4.00);"> <br>
<br>
<br> <inputtype=hiddenname=hiddentotalvalue=0>
<input
type=hiddenname=hiddenpriorradiovalue=0> Your total is: <inputtype=textname=totalreadonly> <br>
<br> (Note: Total can not be changed by the
visitor.) </font> </form>