beegled
asked on
Further problems with totaling script
I have had help with this one before but now a new problem was discovered with it. If in the first
price field, you enter a $, it does not total as it should and causes errors. It doesn't work and causes errors when you use the auto-complete feature
that is built into IE to fill in the quantity field. Here is the script:
<SCRIPT LANGUAGE="JavaScript">
function dp(price)
{
string = "" + price;
number = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (number == 1)
return string + '00';
if (number == 2)
return string + '0';
if (number > 3)
return string.substring(0,string. length-num ber+3);
return string;
}
function calculate()
{
document.Request.totalA.va lue = dp((document.Request.Qty_A .value)*(d ocument.Re quest.Pric e_A.value) )
document.Request.totalB.va lue = dp((document.Request.Qty_B .value)*(d ocument.Re quest.Pric e_B.value) )
document.Request.totalC.va lue = dp((document.Request.Qty_C .value)*(d ocument.Re quest.Pric e_C.value) )
document.Request.totalD.va lue = dp((document.Request.Qty_D .value)*(d ocument.Re quest.Pric e_D.value) )
document.Request.totalE.va lue = dp((document.Request.Qty_E .value)*(d ocument.Re quest.Pric e_E.value) )
document.Request.totalF.va lue = dp((document.Request.Qty_F .value)*(d ocument.Re quest.Pric e_F.value) )
document.Request.totalG.va lue = dp((document.Request.Qty_G .value)*(d ocument.Re quest.Pric e_G.value) )
document.Request.totalH.va lue = dp((document.Request.Qty_H .value)*(d ocument.Re quest.Pric e_H.value) )
document.Request.Total_Val ue.value = dp(eval(document.Request.t otalA.valu e) + eval(document.Request.tota lB.value)
+ eval(document.Request.tota lC.value) + eval(document.Request.tota lD.value) + eval(document.Request.tota lE.value)
+ eval(document.Request.tota lF.value) + eval(document.Request.tota lG.value) + eval(document.Request.tota lH.value))
}
/*function regExp(ele)
{
d=ele.value.indexOf('.')
dot=/\./g
e=ele.value.substr(0,d+1)
if(d!=-1){e+=ele.value.sub str(d+1, ele.value.length).replace( dot,'')}
re=/[^0-9.]+/g
ele.value=e.replace(re,'')
calculate()
}*/
function regExp(ele)
{
d=ele.value.indexOf('.');
dot=/\./g;
if(d!=-1){
e=ele.value.substr(0,d+1);
e+=ele.value.substr(d+1, ele.value.length).replace( dot,'');
}
re=/[^0-9.]+/g;
ele.value=ele.value.replac e(re,'');
calculate();
}
</SCRIPT>
Here is an example of a line item:
<TR>
<TD><p align="left"><FONT face="arial, helvetica" size=2>B)</FONT></p></TD>
<TD align=middle><p align="center"><INPUT size=12 name=Item_B value="<%=Session("Item_B" )%>"></p>< /TD>
<TD align=middle><p align="center"><INPUT size=2 name=Qty_B onChange="calculate()" value="<%=Session("QTY_B") %>"></p></ TD>
<TD align=middle><p align="center"><INPUT size=18 name=Description_B value="<%=Session("Descrip tion_B")%> "></p></TD >
<TD align=middle><p align="center"><INPUT size=10 name=Price_B onChange="regExp(this)" value="<%=Session("Price_B ")%>"><FON T
face="arial, helvetica" size=2>EA.</FONT></p></TD>
</TR>
The toaling is done with hidden fields:
<input type="hidden" name="totalA">
<input type="hidden" name="totalB">
<input type="hidden" name="totalC">
<input type="hidden" name="totalD">
<input type="hidden" name="totalE">
<input type="hidden" name="totalF">
<input type="hidden" name="totalG">
<input type="hidden" name="totalH">
Any ideas what is wrong with it to cause it to do this? Any help is greatly appreciated.
price field, you enter a $, it does not total as it should and causes errors. It doesn't work and causes errors when you use the auto-complete feature
that is built into IE to fill in the quantity field. Here is the script:
<SCRIPT LANGUAGE="JavaScript">
function dp(price)
{
string = "" + price;
number = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (number == 1)
return string + '00';
if (number == 2)
return string + '0';
if (number > 3)
return string.substring(0,string.
return string;
}
function calculate()
{
document.Request.totalA.va
document.Request.totalB.va
document.Request.totalC.va
document.Request.totalD.va
document.Request.totalE.va
document.Request.totalF.va
document.Request.totalG.va
document.Request.totalH.va
document.Request.Total_Val
+ eval(document.Request.tota
+ eval(document.Request.tota
}
/*function regExp(ele)
{
d=ele.value.indexOf('.')
dot=/\./g
e=ele.value.substr(0,d+1)
if(d!=-1){e+=ele.value.sub
re=/[^0-9.]+/g
ele.value=e.replace(re,'')
calculate()
}*/
function regExp(ele)
{
d=ele.value.indexOf('.');
dot=/\./g;
if(d!=-1){
e=ele.value.substr(0,d+1);
e+=ele.value.substr(d+1, ele.value.length).replace(
}
re=/[^0-9.]+/g;
ele.value=ele.value.replac
calculate();
}
</SCRIPT>
Here is an example of a line item:
<TR>
<TD><p align="left"><FONT face="arial, helvetica" size=2>B)</FONT></p></TD>
<TD align=middle><p align="center"><INPUT size=12 name=Item_B value="<%=Session("Item_B"
<TD align=middle><p align="center"><INPUT size=2 name=Qty_B onChange="calculate()" value="<%=Session("QTY_B")
<TD align=middle><p align="center"><INPUT size=18 name=Description_B value="<%=Session("Descrip
<TD align=middle><p align="center"><INPUT size=10 name=Price_B onChange="regExp(this)" value="<%=Session("Price_B
face="arial, helvetica" size=2>EA.</FONT></p></TD>
</TR>
The toaling is done with hidden fields:
<input type="hidden" name="totalA">
<input type="hidden" name="totalB">
<input type="hidden" name="totalC">
<input type="hidden" name="totalD">
<input type="hidden" name="totalE">
<input type="hidden" name="totalF">
<input type="hidden" name="totalG">
<input type="hidden" name="totalH">
Any ideas what is wrong with it to cause it to do this? Any help is greatly appreciated.
note that those are all single quotes.
-corey
-corey
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Any ideas on why the script does not work when somebody fills in the fields using the auto-complete feature that is built into IE? Thanks so much for help by the way.
ASKER
Wish I culd have solved the whole problem but this was great. Thanks!
If you want to solve it if they use the autocomplete feature you'll need to add an onsubmit function that goes through the form after it's all filled out.
Peter Tracey
Developer
Peter Tracey
Developer
ASKER
Thank you.
---code---
.replace( '$', '' )
---code---
to the end of each
---code---
document.Request.Price_XXX
---code---
line so you have
---code---
document.Request.Price_XXX
---code---
-corey