Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    215
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Javascript error need help!

    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:
    Code:
    <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):
    Code:
    whattowrite += "<a href=\"checkout.html\" onClick=\"deleteItem('"+Xname[i]+"');\" >";
    Hope someone can help me with this.
    Last edited by Kor; 08-24-2007 at 09:27 AM. Reason: wrap the code [code][/code]

  • #2
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    Java and Javascript are not the same thing. Moved.
    "To iterate is human, to recurse divine." -L. Peter Deutsch

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    215
    Thanks
    6
    Thanked 0 Times in 0 Posts
    sorry posted it wrong

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    function deleteItem(item) {
    for (var i = 0; i < Xname.length; i++){
    if (item == Xname[i]) { quant[i] = 0; WriteCookie(); break;}}
    window.location.reload();}

  • #5
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    215
    Thanks
    6
    Thanked 0 Times in 0 Posts
    That didn't do the trick. Could anything else be wrong?

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    I see nothing else wrong.

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

  • #7
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    215
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Hmm firebug says
    Code:
    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"?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    215
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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).

  • #10
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    215
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I found this error with ms script editor: line 106 char 42

    Code:
    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???

  • #11
    Regular Coder
    Join Date
    Jul 2007
    Location
    Velsen Noord, Netherlands
    Posts
    215
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •