I took over this website a little while back. The order form will only update the first three products, and that's only if I comment out the getTaxRate function. It doesn't update the Final Total either. I've made some attempt at getting it to work but ended up pulling my hair out. I'm not too familiar with javascript, but it seems like the code was written poorly. I would appreciate any help.
return 0; // Okey Dokey!
}
function formatCurrency(nAmount)
{
//-- Returns passed number as string in $xxx,xxx.xx format.
nAmount=eval(nAmount)
workNum=Math.abs((Math.round(nAmount*100)/100));workStr=""+workNum
if (workStr.indexOf(".")==-1){workStr+=".00"}
dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
pStr=workStr.substr(workStr.indexOf("."))
while (pStr.length<3){pStr+="0"}
//--- Adds comma in thousands place.
if (dNum>=1000)
{
dLen=dStr.length
dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
}
//-- Adds comma in millions place.
if (dNum>=1000000)
{
dLen=dStr.length
dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
}
retval = dStr + pStr
//-- Put numbers in parentheses if negative.
if (nAmount<0) {retval="("+retval+")"}
return "$"+retval
}
function getTaxRate()
{
// Need to get the correct tax rate based upon what State.
// Get the state the user is shipping to.
/* nStateIDX = document.formSalesOrder.elements["BillingState"].selectedIndex;
strState = document.formSalesOrder.elements["BillingState"].options[nStateIDX].value;
nTaxRate = 0.00;
if ( strState == "MI - Michigan" )
{
// If the selected state is 'MI - Michigan' then return the correct tax
nTaxRate = 6.000000;
}
return nTaxRate/100;*/
}
function getShippingRate()
{
// Shipping is a fixed percentage rate
var nRate = 0.000000/100;
return nRate;
}
function updateTotal()
{
var dSubtotal = 0.00;
var dShipping = 0.00;
var dTax = 0.00;
var dTotal = 0.00;
Best thing to do is to step through it with a script debugger. Firefox has a free one called Firebug. If you have any MS application development tools, then you probably have the MS Script Debugger for IE, too.
02-10-2009, 08:18 PM
neoseeker191
Alright I ran the debugger and the iCnt value was always 3 no matter which product I chose. I found this odd, shouldn't it change? And why is it always 3?
02-10-2009, 08:21 PM
MrNobody
iCnt is not an important variable -- it is only a loop counter. Since you have three products, the loop counter will always be 3 after the loop is complete.
02-10-2009, 08:24 PM
neoseeker191
But I have more than 3 products, I have 10.
02-10-2009, 08:25 PM
neoseeker191
But I don't have 3 products I have 10.
02-10-2009, 08:32 PM
MrNobody
OK, then you need to step through it with the debugger and find out why the loop doesn't complete for all 10 of your products. If you want to post a live link to the page on your servers, then I can check it out in my browser with my debugger, too.
02-10-2009, 08:35 PM
neoseeker191
I did, it's in my first post.
02-10-2009, 08:46 PM
MrNobody
Well, you haven't been checking for your error messages in your browser. An error is generated every time you try to pick a quantity. This also means you didn't do a very good job of stepping through your code with the debugger -- because the debugger would have puked on this statement:
...and each one like it after that. This also explains why iCnt is always a 3 -- because that is where your script fails and that represents the field which does not exist in your page: QTY_4_TxTrayKT_DS. You actually have these:
Well I've never used a browser debugger before, I'm not sure how to step through. How do you step through and why does it error out?
02-10-2009, 08:55 PM
MrNobody
See updated post above.
02-10-2009, 09:05 PM
neoseeker191
What a dumb mistake on my part, simple spelling errors. It works now thank you for your help. By the way how did you step through the javascript, I have firebug with Firefox.
02-10-2009, 09:08 PM
MrNobody
I used Firebug, too.
Open Firebug
Set the Firebug Option to Break on All Errors
Refresh your page (to catch errors during page load)
Select a quantity
Firebug stops your script at the first error
02-10-2009, 09:14 PM
neoseeker191
Okay I think I did that same thing when I was debugging, except I couldnt tell that it stopped on that statement you told me. How did you know that it was the error and that it was looking for a value that didn't exist?
02-10-2009, 09:49 PM
MrNobody
1 Attachment(s)
See the attached image for an explanation using your page as the example.