robinski
asked on
Addition with Java script
I have a simple form that calculates and adds items into a "Total" field.
How do I add a fixed amount for delivery?
Here is the code for the last of twenty items and the code for the Total.
<TD align=right width="25%"><FONT face=Arial
size=3>Professional</FONT> </TD>
<TD align=right width="30%"><B><FONT face=Arial
size=3>$435.00</FONT></B>< /TD>
<TD width=50><INPUT
onchange=this.form.total.v alue=check Choice(thi s); size=3 value=0
name=KP price="435.00" priorval="0"> </TD></TR>
<TR>
<TR>
<TD width="85%" colspan="4"><B><FONT face=Arial
size=3>Total:
<INPUT readOnly size=12
name=total></FONT></B>
Many thanks,
robinski
How do I add a fixed amount for delivery?
Here is the code for the last of twenty items and the code for the Total.
<TD align=right width="25%"><FONT face=Arial
size=3>Professional</FONT>
<TD align=right width="30%"><B><FONT face=Arial
size=3>$435.00</FONT></B><
<TD width=50><INPUT
onchange=this.form.total.v
name=KP price="435.00" priorval="0"> </TD></TR>
<TR>
<TR>
<TD width="85%" colspan="4"><B><FONT face=Arial
size=3>Total:
<INPUT readOnly size=12
name=total></FONT></B>
Many thanks,
robinski
ASKER
OOOOPS
My apology this must be the missing piece:
<!-- Begin
function checkChoice(whichbox) {
with (whichbox.form) {
if (isNaN(whichbox.value)) {
whichbox.value = whichbox.priorval;
whichbox.focus();
}
whichbox.value = Math.abs(whichbox.value);
var dec = whichbox.value.indexOf('.' , 1)
if (dec > 0) {
alert('No decimal places allowed for \"' +whichbox.name +'\" !');
whichbox.value = whichbox.priorval;
whichbox.focus();
}
hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.price * whichbox.priorval);
whichbox.priorval = whichbox.value;
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price * whichbox.value);
return(formatCurrency(hidd entotal.va lue));
}
}
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.valu e = '$0';
document.myform.hiddentota l.value = 0;
for (xx = 0; xx < document.myform.elements.l ength; xx++) {
if (document.myform.elements[ xx].type == 'text') {
document.myform.elements[x x].value = 0;
}
}
}
// End -->
My apology this must be the missing piece:
<!-- Begin
function checkChoice(whichbox) {
with (whichbox.form) {
if (isNaN(whichbox.value)) {
whichbox.value = whichbox.priorval;
whichbox.focus();
}
whichbox.value = Math.abs(whichbox.value);
var dec = whichbox.value.indexOf('.'
if (dec > 0) {
alert('No decimal places allowed for \"' +whichbox.name +'\" !');
whichbox.value = whichbox.priorval;
whichbox.focus();
}
hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.price * whichbox.priorval);
whichbox.priorval = whichbox.value;
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price * whichbox.value);
return(formatCurrency(hidd
}
}
function formatCurrency(num) {
num = num.toString().replace(/\$
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
return ("$" + num + "." + cents);
}
function InitForm() {
document.myform.total.valu
document.myform.hiddentota
for (xx = 0; xx < document.myform.elements.l
if (document.myform.elements[
document.myform.elements[x
}
}
}
// End -->
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Very many thanks. You help is appreciated
ASKER
Very many thanks. You help is appreciated
there must be code that updates the total value you have to modify that code so that you add the fixed delivery fee to it.. I can't figure it out from just this snippet