...

View Full Version : Javascript error need help!



UD2006
08-23-2007, 11:30 PM
The shoppingsystem I've made works very well, only when I've added a painting to my shoppingcart and goto the shoppingcart and remove the painting, click the return shopping (dutch) button and try to add the same painting, the painting isn't added to the shoppingcart and IE 7 gives the following error, but I know the problem has to be with the function deleteItem.

The problem isn't there when I empty the whole cart, only when deleting an item.

I've tested it with ie, safari and firefox and only ie gives the problem.

Problem listed Bold is what I think the problem.

Here is the whole script:


<script language="JavaScript" type="text/javascript">
<!--
var NewEoc2 = document.cookie;
var ShipTotal=0;
var Total=0;
var SaleTotal=0;
var X1 ="";
var X2 =0;
var X3 =0;
var X4 =0;
var today = new Date();
var expiry = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1000);
var Xname = new Array();
var sdesc = new Array();
var cost = new Array();
var ship = new Array();
var quant = new Array();
var urls = new Array();
var comments = new Array();
var f = document.form;
var value;
var found = 0; var whattowritepp = "";
var CookieAll;
var TotalQuant=0;
var TotalProducts=0;
var SubTotals;
var DiscountAmt= 0;


function getallCookie() {
//new spanning code
var whole_cookie = document.cookie;
var each_cookie = whole_cookie.split(";") ;
var value ="";

var index;

for (var i=0; i< each_cookie.length;i++){
index = each_cookie[i].indexOf("NewEoc2=");
if( index != -1) {
index = each_cookie[i].split("=");
value += unescape(index[1]);

}
}

for(var j=0; j<each_cookie.length;j++){
index = each_cookie[j].indexOf("NewEoc2"+j+"=");
if( index != -1) {
index = each_cookie[j].split("=");
value += unescape(index[1]);
}
}

return unescape(value);
}



function WriteCookie(){
var value ="";
value = escape(ShipTotal) || 0;
value += "^~^"
value += escape(X1) || "";
value += "^~^"
value += escape(X2) || 0;
value += "^~^"
value += escape(X3) || 0;
value += "^~^"
value += escape(X4) || 0;
value += "^~^"
var IEbrowser = false;
if ( navigator.appName == "Microsoft Internet Explorer") {iebrowser = true;}
var kk = 3825
var jj = 0;
var nn = 0;
var CookieHold = "";
var CookieLen = 0;
do {
for (var i = nn; CookieLen < kk && i < Xname.length; i++){
value += escape(Xname[i]) + "^~^" + escape(sdesc[i]) + "^~^" + escape(cost[i]) + "^~^"+ escape(ship[i]) + "^~^" + escape(quant[i]) + "^~^";
if (i+1 >= Xname.length){break;}
if (value != null && value != "") {
nn++;
CookieLen = value.length;
}
}
if (IEbrowser == true && CookieLen >= kk ) {
alert("Please checkout now, your cart is full");
break;
}
if (jj > 0 ) {
if (value != null && value != "") {
CookieHold = "NewEoc2"+jj+"=" + value + ";";
document.cookie= "NewEoc2"+jj+"=" + value + "; expires=" + expiry.toGMTString()+";path=/;";}
}
else {
CookieHold = "NewEoc2=" + value + ";";
document.cookie= "NewEoc2=" + value + "; expires=" + expiry.toGMTString()+";path=/;";
}
CookieLen = CookieHold.length;
value = "";
jj++;
if (nn >= Xname.length) {break;}
if (nn + jj >= Xname.length) {break;}
if (jj > 14){ alert("Please checkout now, your cart is full");break;}
CookieLen = 0;
} while (nn <= Xname.length);
}




function OpenIn(NewLocation) {document.location = NewLocation;return false;}


function round(number) { number = Math.round(number*Math.pow(10,2))/Math.pow(10,2);
return (number == Math.floor(number)) ? number + '.00' : ( (number*10 == Math.floor(number*10)) ? number + '0' : number); }



function deleteItem(item) {
for (var i = 0; Xname.length; i++){
if (item == Xname[i]) { quant[i] = 0; WriteCookie(); break;}}
window.location.reload();}



function EmptyCart() {
var value="";
document.cookie= "NewEoc2=" + escape(value) + "; expires=" + expiry.toGMTString()+";path=/;";
for(var i=1;i < 21;i++){
if( document.cookie.indexOf("NewEoc2"+i+"=") != -1) {
document.cookie= "NewEoc2"+i+"=" + escape(value) + "; expires=" + expiry.toGMTString()+";path=/;";}}
NewEoc2 = document.cookie;
window.location.reload();}



function setCookie2(item,NewValue) {
for (var i = 0; Xname.length; i++){
if (item == Xname[i]) {
quant[i] = NewValue;
TotalQuant = 0; var j = 0;
for (var i = 0; i < Xname.length; i++) {
if (quant[i] >0){
TotalQuant = TotalQuant+quant[i]*1;
j = i+1;
indTotal = cost[i]*quant[i];
}}
TotalProducts = TotalQuant ;
SubTotals = indTotal;
ShipTotal = 0;
SetShip2();
WriteCookie();
break;}}
window.location.reload();}



function AddShip(selected) {
WriteCookie();
window.location.reload();}



function SetShip(){
var shipfound = 0;
var f = document.form77.state_picked;
}
function SetShip2(){
var shipfound = 0;
}


function GetFromCart() {
var CookieAll = getallCookie();
if (CookieAll == null) {
} else {
var EachCookie = CookieAll.split("^~^");
ShipTotal = EachCookie[0] || 0 ;
ShipTotal = ShipTotal * 1;
X1 = EachCookie[1] || "" ;
X2 = EachCookie[2] || 0 ;
X2 = X2 * 1;
X3 = EachCookie[3] || 0 ;
X3 = X3 * 1;
X4 = EachCookie[4] || 0 ;
X4 = X4 * 1;
var j=0;
for (var i = 5; i < EachCookie.length; i=i+5){
Xname[j] = EachCookie[i] || 0;
sdesc[j] = EachCookie[i+1] || 0;
cost[j] = EachCookie[i+2] || 0;
ship[j] = EachCookie[i+3] || 0;
quant[j] = EachCookie[i+4] || 0;
j++;}}

var whattowrite = "";
TotalQuant = 0;
for (i = 0; i < Xname.length; i++) {
if (quant[i] >0){
TotalQuant += quant[i]*1;
j = i+1;
indTotal = cost[i]*quant[i];
Total += indTotal;
whattowrite += "<tr><td>" + sdesc[i] + "</td>"
whattowrite += "<td align=center>" + cost[i] + "</td>"
whattowrite += "<td align = center>"
whattowrite += "<input name=\"t"+ j
whattowrite += "\" size=6 value=\""+quant[i]+"\">";
whattowrite += "<a href=\"checkout.html\" onClick=\"setCookie2('"+Xname[i]+"',document.form77.t"+ j +".value);\" >";
whattowrite += "<img src=\"verander.gif\" border=\"1\" alt=\"Verander\" ></a>";
whattowrite += "</td>"
whattowrite += "<td align=center>"+ round(indTotal)+ "</td>"
whattowrite += "<td align=center>"
whattowrite += "<a href=\"checkout.html\" onClick=\"deleteItem('"+Xname[i]+"');\" >";
whattowrite += "<img src=\"verwijder.gif\" border=\"1\" alt=\"Verwijder\" ></a>";

whattowrite += "</td></tr>"
}
}
if (Total > 0) { Total += X2; }
TotalProducts = TotalQuant ;
SubTotals = Total;
var SaleTotal = 0;
SetShip2();
var xShipTotal=0;xShipTotal=ShipTotal;if (ShipTotal > 0 && Total > 0 ) { whattowrite += "<tr class=\"COShippingLine\"><td colspan=\"4\"> \ </td>"
whattowrite += "<td>Shipping Total"
whattowrite += "<input name=\"stotal\""
whattowrite += " type=hidden value=\""+xShipTotal+"\"></td>";
whattowrite += "<td align = center>"+ round(xShipTotal)+ "</td></tr>"}
if (Total > 0) {Total += xShipTotal + SaleTotal ;}
whattowrite += "<tr class=\"COEmptyCartLine\" ><td>"
whattowrite += "<a href=\"checkout.html\" onClick=\"EmptyCart();\"><img src=\"leeg mandje.gif\" border=\"1\" ></a>";
whattowrite += "</td><td colspan=\"1\"> \ </td>"
whattowrite += "<td>Totaal:"
whattowrite += "<input name=\"total\""
whattowrite += " type=hidden value=\""+round(Total)+"\"></td>";
whattowrite += "<td align = center>"+ round(Total)+ "</td>"
whattowrite += "<td> </td></tr>"
if (whattowrite==""){whattowrite="<tr><td align=center colspan=\"6\">"
whattowrite = whattowrite + "Uw mandje is leeg</td></tr>";}
document.write(whattowrite); }


//-->
</script>

And here is the line that isn't right (I think):


whattowrite += "<a href=\"checkout.html\" onClick=\"deleteItem('"+Xname[i]+"');\" >";

Hope someone can help me with this.

Aradon
08-24-2007, 12:24 AM
Java and Javascript are not the same thing. Moved.

UD2006
08-24-2007, 10:05 AM
sorry posted it wrong :)

Philip M
08-24-2007, 02:00 PM
function deleteItem(item) {
for (var i = 0; i < Xname.length; i++){
if (item == Xname[i]) { quant[i] = 0; WriteCookie(); break;}}
window.location.reload();}

UD2006
08-24-2007, 03:13 PM
That didn't do the trick. Could anything else be wrong?

Philip M
08-24-2007, 04:12 PM
I see nothing else wrong.

You say "IE 7 gives the following error" What is the error message?

UD2006
08-24-2007, 05:00 PM
You can check for yourself at the website http://www.artcreations.nl/schilderijen_dieren.html (its dutch)by adding a painting to the cart (voeg toe aan mandje), delete it (verwijder) (not empty cart), then continue shopping (winkel verder) and try to add the same painting, it won't add it. This problem only happends with IE, with safari and firefox this problem isn't there.

Someone else tested this also and said that with butterfly.html at line 100 an error was shown. This line is the calculate function, so I think that the problem lies there.

abduraooft
08-24-2007, 05:13 PM
Hmm firebug says

f.total has no properties
[Break on this error] Saletotal = Saletotal * 1; f.total.value = round(Total);
dieren.html (line 169)

Where is your input control named "total"?

UD2006
08-24-2007, 05:39 PM
If you look at the function calculate, at butterfly.html (the top painting at dieren.html), I think that it's there where the is Total explained.

Because I can even work without the page dieren.html, so this page doesn't count (it should only contain the index of pictures).

UD2006
08-31-2007, 07:58 AM
I found this error with ms script editor: line 106 char 42


f.tOption819A.value = round(document.form.Option819A[document.form.Option819A.selectedIndex].value * 53);continue;

This could be the trouble maker. But don't how to solve it.

Anybody an idea???

UD2006
09-06-2007, 12:19 PM
I've found the solution, I had to made the hidden object visible and the page had to be equal to the item.

Thanks for all your help guys.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum