Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am seriously script dumb!

Status
Not open for further replies.

AMysticWeb

Technical User
Oct 20, 2002
309
US
Back again,

I am not a script person, but I keep trying to modify this script and get it working.

Not sure where I am screwing this up. I tried to follow the script process to the letter, but I must have missed something.

Item 01 and 02 don't total.
Item 03 and 04 total, but I can't get all four of them to total together. It just adds the $25 and $75 dollar amounts.

Thanks for taking the time to look.

---------------------------

<!-- Script Courtesy of Texas Web Developers
<SCRIPT language=JavaScript>
function asMoney(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
cents = Math.floor((num*100+0.5)%100);
num = Math.floor(num).toString();
if(cents < 10) cents = "0" + cents;
return (num + '.' + cents);
}

function addSubtotal(){
var ad1 = document.Form1.Item01Total.value*1
var ad1 = document.Form1.Item02Total.value*2
var ad1 = document.Form1.Item03Total.value*3
var ad1 = document.Form1.Item04Total.value*4
var sub=asMoney(ad1)

return sub
}

function addQty(){
var qt = document.Form1.Item01Qty.value*1
var qt = document.Form1.Item02Qty.value*2
var qt = document.Form1.Item03Qty.value*3
var qt = document.Form1.Item04Qty.value*4
return qt
}



function checkOrder() {

document.Form1.subtot.value=addSubtotal()
document.Form1.qtytot.value=addQty()


return 0

}

//-->
</SCRIPT>

<p>&nbsp;
</p>
<p>&nbsp;</p>
<form name="Form1" method=post action="">


<table width="70%" border="1" bordercolordark="#330099" bordercolorlight="#9999FF" align="center" height="186" bordercolor="#F7F7F7">
<tr>
<td height="37" align="left"> <font face="Arial, Helvetica, sans-serif">
<div align="center"><b><font color="#FFFFFF">Services
Ordered</font></b></div>
</font></td>
<td height="37"> <b><font face="Arial, Helvetica, sans-serif" color="#FFFFFF">&nbsp;&nbsp;<br>
Price<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></b></td>
<td width="12%" height="37">
<div align="center"><b> <font face="Arial, Helvetica, sans-serif" color="#FFFFFF">
Quantity
</font></b></div>
</td>
<td width="21%" height="37"> <font face="Arial, Helvetica, sans-serif">
<div align="center"><b><font color="#FFFFFF">Total</font></b></div>
</font></td>
</tr>
<tr>
<td height="36" align="left"> <font face="Arial, Helvetica, sans-serif">
<div align="center">
<p align="left">&nbsp;</div>
</font></td>
<td height="36"> <font face="Arial, Helvetica, sans-serif" color="#FFFFFF">$12.00</font></td>
<td width="12%" height="36"> <font face="arial, Arial, Helvetica">
<div align="center"> <font face="Arial, Helvetica, sans-serif" color="#FFFFFF">
<input type="text" name="Item01Qty" size="3" maxlength="3" tabindex=1 value="0" onBlur="document.Form1.Item01Total.value=asMoney(12.00*document.Form1.Item01Qty.value)">
</font></div>
</font></td>
<td width="21%" height="36"> <font face="arial, Arial, Helvetica">
<div align="right"> <font face="Arial, Helvetica, sans-serif" color="#FFFFFF">
<input type="text" name="Item01Total" size="7" maxlength="7" value="0.00">
</font></div>
</font></td>
</tr>
<tr>
<td height="23" align="left">
<p align="center"></td>
<td height="23">
<font face="Arial, Helvetica, sans-serif" color="#FFFFFF">$10.00</font></td>
<td width="12%" height="23">
<p align="center"> <font face="Arial, Helvetica, sans-serif" color="#FFFFFF">
<input type="text" name="Item02Qty" size="3" maxlength="3" tabindex=1 value="0" onBlur="document.Form1.Item02Total.value=asMoney(10.00*document.Form1.Item02Qty.value)">
</font></td>
<td width="21%" height="23">
<p align="right"> <font face="Arial, Helvetica, sans-serif" color="#FFFFFF">
<input type="text" name="Item02Total" size="7" maxlength="7" value="0.00">
</font></td>
</tr>
<tr>
<td height="18" align="left">
<p align="center"></td>
<td height="18">
<font face="Arial, Helvetica, sans-serif" color="#FFFFFF">$75.00</font></td>
<td width="12%" height="18">
<p align="center"> <font face="Arial, Helvetica, sans-serif" color="#FFFFFF">
<input type="text" name="Item03Qty" size="3" maxlength="3" tabindex=1 value="0" onBlur="document.Form1.Item03Total.value=asMoney(75.00*document.Form1.Item03Qty.value)">
</font></td>
<td width="21%" height="18">
<p align="right"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF"><input type="text" name="Item03Total" size="7" maxlength="7" value="0.00">
</font></td>
</tr>
<tr>
<td height="18" align="left">
<p align="center"></td>
<td height="18">
<font face="Arial, Helvetica, sans-serif" color="#FFFFFF">$25.00</font></td>
<td width="12%" height="18">
<p align="center"> <font face="Arial, Helvetica, sans-serif" color="#FFFFFF">
<input type="text" name="Item04Qty" size="3" maxlength="3" tabindex=1 value="0" onBlur="document.Form1.Item04Total.value=asMoney(25.00*document.Form1.Item04Qty.value)">
</font></td>
<td width="21%" height="18">
<p align="right"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF"><input type="text" name="Item04Total" size="7" maxlength="7" value="0.00">
</font></td>
</tr>
</table>
<table width="70%" border="1" cellspacing="0" cellpadding="0" align="center" height="70" bordercolor="#F7F7F7">
<tr>
<td width="50%" height="22"><font color="#FFFFFF">&nbsp;</font> </td>
<td width="35%" height="22"> <font face="Arial, Helvetica,sans-serif">
<div align="right"><font color="#FFFFFF"><font face="Arial, Helvetica, sans-serif">Total Amount
Due</font>:</font></div>
</font></td>
<td width="15%" height="22"> <font face="Arial, Helvetica, sans-serif">
<input type="text" name="subtot" size="7" maxlength="7">
</font></td>
</tr>
<tr>
<td width="85%" colspan="2" height="26"> <font face="Arial, Helvetica, sans-serif" color="#FFFFFF">
<input type="hidden" name="qtytot">&nbsp;&nbsp;
<input type="button" name="calc" value="Calculate" onClick="checkOrder()" tabindex=35 style="color: #F7F7F7; background-image: url('blk_dotsbg.gif'); border: 1 solid #F7F7F7">
</font></td>
<td width="15%" height="26"><font face="arial, Arial, Helvetica">
&nbsp;
</font> <font face="Arial, Helvetica, sans-serif" color="#FFFFFF">
<input type="button" name="calc1" value="Clear" onClick="checkOrder()" tabindex=35 style="color: #F7F7F7; background-image: url('blk_dotsbg.gif'); border: 1 solid #F7F7F7">
</font><font face="arial, Arial, Helvetica">
</font></td>
</tr>
</table>

</form>
---------------------------

Hope I have been of some help,
Micheal

FrontPage Form Tutorials & Form Script Examples
 

Try changing your addSubtotal and addQty functions to read:

Code:
function addSubtotal() {
    var ad1 = document.Form1.Item01Total.value*1;
    var ad1 += document.Form1.Item02Total.value*2;
    var ad1 += document.Form1.Item03Total.value*3;
    var ad1 += document.Form1.Item04Total.value*4;
    return (asMoney(ad1));
}

function addQty(){
    var qt = document.Form1.Item01Qty.value*1;
    var qt += document.Form1.Item02Qty.value*2;
    var qt += document.Form1.Item03Qty.value*3;
    var qt += document.Form1.Item04Qty.value*4;
    return (qt);
}

Hope this helps,
Dan

 
Hi Dan,

Thanks for the quick response.

The new code just generated errors.

Here is a link to the original.


I am trying to add items, but the new ones don't tatal. Could this be something with the first part of the script?

Hope I have been of some help,
Micheal

FrontPage Form Tutorials & Form Script Examples
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top