Web Analytics Made Easy -
StatCounter Trouble with <body onLoad="..."> not running ..? - CodingForum


No announcement yet.

Trouble with <body onLoad="..."> not running ..?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble with <body onLoad="..."> not running ..?

    I need to run a javascript function on page load and have included the script. i am using the command <body onLoad="EmptyCart()" which is a function within the included script. Only problem is, it runs the function when i run it on the server i have set up on my home computer, but when uploaded onto my webhosting server, the script just doesn't run. I am assuming that the server must not be allowing onload functions would this be correct? of am i just doing something wrong.

    cheers, Mark.
    [email protected]

  • #2
    No one will be able to help you unless we can see some source code.


    • #3
      here is the source code:

      <title>PostItToMe.com Checkout</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <SCRIPT SRC="language-en.js"></SCRIPT><SCRIPT SRC="nopcart.js">
      // NOP Design JavaScript Shopping Cart ||
      // Visit NOP Design at http://www.nopdesign.com/freecart ||
      <body onLoad = "EmptyCart()" bgcolor="#EEEEEE" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">



      • #4
        Doesn't help much. What's the source of the EmptyCart function? How about showing us the source of nopcart.js and language-en.js so that we can have a look at the actual source of the problem?
        liorean <[[email protected]]>
        Articles: RegEx evolt wsabstract , Named Arguments
        Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
        Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


        • #5
          ok, the language-en.js file is not of much relevence as it is just the english messages etc.
          here is the script source, the EmptyCart() function is the last one.
          Attached Files


          • #6
            You have the contents of the function commented out!
            function EmptyCart()
               var NumberOrdered = 0;    //Number of products ordered
               [color=red]/*[/color]iNumberOrdered = GetCookie("NumberOrdered");
               if ( iNumberOrdered == null )
                  iNumberOrdered = 0;
               for ( i = 1; i <= iNumberOrdered; i++ ) {
                  NewOrder = "Order." + i;
                  DeleteCookie (NewOrder,"/");
               alert("Cart is now empty!");


            • #7
              only the top part is commented out, i am just trying to get it to run at all, so am just interested in the alert line so i know it is running mostly.


              • #8
                So the alert doesn't show at all?
                Maybe you have window.onload handler somewhere below the <body> tag, which overrides the onload handler defined in body tag.
                vBulletin Mods That Rock!


                • #9
                  I ran the codes with a body onload event handler. The alert fires but there is an error thrown on line 135 that bLanguage is undefined. bLanguageDefined is a string used with the language pack.

                  If the O/P made any changes or commented anything out in that script, he/she should look there.


                  FWIW: The site which provided the codes has a forum section just for this script. The link is on their homepage.