|
↑
Forms >>>
Select items in this totals form using checkboxes and radio buttons.
Add the below code to the <body> section of your page:
<script
language="javascript"
type="text/javascript">
function
CheckChoice(whichbox,
Price)
{
with
(whichbox.form)
{
if
(whichbox.type
==
"radio")
{
hiddentotal.value
=
eval(hiddentotal.value)
-
eval(hiddenpriorradio.value);
hiddenpriorradio.value
=
eval(Price);
hiddentotal.value
=
eval(hiddentotal.value)
+
eval(Price);
}
else
{
if
(whichbox.checked
==
false)
{
hiddentotal.value
=
eval(hiddentotal.value)
-
eval(whichbox.value);
}
else
{
hiddentotal.value
=
eval(hiddentotal.value)
+
eval(whichbox.value);
}
}
if
(hiddentotal.value
<
0)
{
InitForm();
}
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);
}
function
InitForm()
{
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;
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;
}
}
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;
}
}
}
</script>
<form
method=POST
name=myform>
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>
<br>
<b>Prepare
with this special sauce (extra charge -- only one selection allowed):</b>
<br>
None, thanks
<input
type=radio
name=Sauce
value=none
onClick="this.form.total.value=CheckChoice(this,
0.00);">
Duck Sauce $10.99
<input
type=radio
name=Sauce
value=duck
onClick="this.form.total.value=CheckChoice(this,
10.99);">
Ginger Sauce $5.00
<input
type=radio
name=Sauce
value=ginger
onClick="this.form.total.value=CheckChoice(this,
5.00);">
Hot Sauce $1.50
<input
type=radio
name=Sauce
value=hot
onClick="this.form.total.value=CheckChoice(this,1.50);">
<br>
<br>
<br>
<input
type=hidden
name=hiddentotal
value=0>
<input
type=hidden
name=hiddenpriorradio
value=0>
Your total is:
<input
type=text
name=total
readonly>
<br>
<br>
(Note: Total can not be changed by the
visitor.)
</font>
</form>
<hr
width=100%
noshade>
<form
method=POST
name=myform2>
Roasted Pig $10.00
<input
type=checkbox
name=Pig
value=10.00
onClick="this.form.total.value=CheckChoice(this);">
Roasted Rat $17.49
<input
type=checkbox
name=Rat
value=17.49
onClick="this.form.total.value=CheckChoice(this);">
Roasted Cat $3.50
<input
type=checkbox
name=Cat
value=3.50
onClick="this.form.total.value=CheckChoice(this);">
<br>
<br>
<b>Prepare
with this special seasoning (extra charge -- only one selection
allowed):</b>
<br>
None, thanks
<input
type=radio
name=Season
value=none
onClick="this.form.total.value=CheckChoice(this,0.00);">
Liquid Nitrogen $17.50
<input
type=radio
name=Season
value=nitrogen
onClick="this.form.total.value=CheckChoice(this,17.50);">
Gun Powder $8.50
<input
type=radio
name=Season
value=gunpowder
onClick="this.form.total.value=CheckChoice(this,
8.50);">
Vodka $4.00
<input
type=radio
name=Season
value=vodka
onClick="this.form.total.value=CheckChoice(this,
4.00);">
<br>
<br>
<br>
<input
type=hidden
name=hiddentotal
value=0>
<input
type=hidden
name=hiddenpriorradio
value=0>
Your total is:
<input
type=text
name=total
readonly>
<br>
<br>
(Note: Total can not be changed by the
visitor.)
</font>
</form>
|
→ casino games online
|