Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2006
    Posts
    420
    Plugin Contributions
    0

    Default Javascript error - help please

    Hi , I have just written a simple bit of JavaScript to create Parcel tracking , but it is erroring when i insert it into Zen-cart

    It works fine as a standalone html page on the same server , but as soon as I add the script into HTML_Header it errors on page with IE7 giving the error : Object Expected

    Code:
    <script language="javascript" type="text/javascript" runat="server">
    function goTrackit2(){
                var target = 'http://www.interlinkexpress.com/service/tracking?consignment=' + document.getElementById('consignment2').value;
                if (document.getElementById('consignment2').value != "")
                {
                            document.form1.action = 'http://www.interlinkexpress.com/service/tracking?consignment=' + document.getElementById('consignment2').value;
                            document.form1.submit();
                }
                else
                {
                            alert("You didn't type in a tracking number");
                }
    }
    
    </script>
    It still works fine , but with an IE error , its going to put people off my site.
    It works fine with no errors in firefox ( i love FF ! )


    Any guru's out there give me any clues ?
    Various Zen cart sites !

  2. #2
    Join Date
    Jan 2004
    Posts
    66,445
    Plugin Contributions
    81

    Default Re: Javascript error - help please

    Your var target= line is referencing an object that doesn't exist yet on the page.
    Perhaps define it as an empty string, and then AFTER your IF statement, add the URL to it.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jan 2006
    Posts
    420
    Plugin Contributions
    0

    Default Re: Javascript error - help please

    Excellent thanks , that did the trick.

    If anyone needs the code to put parcel tracking for interlink on their site , let me know.
    Various Zen cart sites !

  4. #4
    Join Date
    Jan 2006
    Posts
    420
    Plugin Contributions
    0

    Default Re: Javascript error - help please

    Actually NO ! it didnt do the trick !

    The page loads fine the first time, as soon as you do a refresh it errors with the same "Object expected"

    The code is now being called from a .js file from the Header_html.php

    Code:
    function goTrackit(){
                if (document.getElementById('consignment').value != "")
                {
                  document.form1.action = 
    'http://www.interlinkexpress.com/service/tracking?consignment=' + 
    document.getElementById('consignment').value;
                            document.form1.submit();
                }
                else
                {
                           window.alert("You didn't type in a tracking number");
                }
    }

    It works standalone , but soon as zen gets hold of it , it errors , I have changed the code slightly again , so not using "target" anymore.

    Any suggestions welcome again !

    PM me if you want the URL as don't want google to spider it yet !

    Cheers MARK
    Various Zen cart sites !

  5. #5
    Join Date
    Jan 2004
    Posts
    66,445
    Plugin Contributions
    81

    Default Re: Javascript error - help please

    You'll get "Object Expected" errors if the object doesn't exist as you described it in your code.

    Thus, if there is no object with the ID of "consignment", or if that object has no value attribute (ie: isn't an input field that can contain a value) then any references to document.getElementById('consignment').value will fail.

    Either your DOM description of the object is not correct or the object doesn't exist on the page you're loading.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    Jan 2006
    Posts
    420
    Plugin Contributions
    0

    Default Re: Javascript error - help please

    hmmm Im confused .

    the element/object does exist and it is an input with a value attribute, which is confirmed when it works.

    I have tried including the script so that it loads after the input element but that made no difference.

    asside from that I can't see what else is wrong unless I have to force the javascript to load last to make sure all the elements exist already?

    my side box code is simply :-

    Code:
    <form name="form1" method="post" target="_blank">
    <input ID="consignment" name="consignment" type="text">
    <input value="Track It" onclick="goTrackit();" type="button">
    </form>
    Various Zen cart sites !

  7. #7
    Join Date
    Jul 2007
    Posts
    1
    Plugin Contributions
    0

    Default Re: Javascript error - help please

    i am having same problem if i run javascript code stand alone in html it works fine but after intigration into zencart it fails. i am calling a php file with javascript at zen central area. i have written three different kind of javascript codes for a double slider and all of them failed while intigration to zencart

  8. #8
    Join Date
    Jan 2004
    Posts
    66,445
    Plugin Contributions
    81

    Default Re: Javascript error - help please

    Where can this be seen in action?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  9. #9
    Join Date
    Jan 2006
    Posts
    420
    Plugin Contributions
    0

    Default Re: Javascript error - help please

    My Error can be seen at tapes-direct.co.uk then forward slash trial

    Had to write it like that so it doesn't get spidered .

    It doesnt error in FF just in I>E and only the Second time you run the page.

    Cheers
    Various Zen cart sites !

 

 

Similar Threads

  1. Please help with configuring a JavaScript File
    By ardhill in forum General Questions
    Replies: 4
    Last Post: 21 Apr 2011, 04:55 PM
  2. Javascript Error? Help?
    By joyjoy in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 6 Jan 2011, 03:36 AM
  3. A little (ok a lot) of javascript help needed please
    By 0be1 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 23 Aug 2008, 02:16 PM
  4. Javascript error, need help!
    By MCanes in forum General Questions
    Replies: 1
    Last Post: 30 Apr 2008, 09:07 PM
  5. my Javascript functions are not working. Please help.
    By milobloom in forum General Questions
    Replies: 8
    Last Post: 13 Jan 2008, 02:25 AM

Posting Permissions

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