Opera doesn't like Javascript object, but IE, Firefox, Safari do

Discussion in 'Javascript' started by Tim Slattery, Jan 22, 2008.

  1. Tim Slattery

    Tim Slattery Guest

    I've used a script provided by Stickman (http://www.the-stickman.com),
    which allows a variable number of files to be uploaded from an HTML
    page. In a nutshell, when a file is selected, it hides that <input
    type="file"...> element, puts the name of the file selected in text on
    the page, and creates a new <input...> element. A bit klunky, but it
    works.

    I've now tested this on IE6, IE7, Firefox, Safari (3.0 for Windows, I
    haven't got the Mac version to go yet), and they have no problem with
    it. But Opera does.

    I include an external javascript file ("mutifile.js") in the head
    section of my HTML page. The first thing in this script is

    function MultiSelector( list_target, max ){


    which defines the MultiSelector object. Way down toward the bottom of
    the page is a short javascript block which invokes this object:

    <script type="text/javascript">
    <!-- Create an instance of the multiSelector class, pass it
    the output target and the max number of files -->
    var multi_selector = new
    MultiSelector(document.getElementById('files_list'), 0);
    <!-- Pass in the file element -->
    multi_selector.addElement(document.getElementById('fname'));
    </script>

    Opera gives this message:

    Reference to undefined variable: MultiSelector

    Why doesn't Opera know what this object is?

    --
    Tim Slattery

    http://members.cox.net/slatteryt
    Tim Slattery, Jan 22, 2008
    #1
    1. Advertising

  2. Re: Opera doesn't like Javascript object, but IE, Firefox, Safarido

    Tim Slattery wrote:

    > I include an external javascript file ("mutifile.js") in the head
    > section of my HTML page. The first thing in this script is
    >
    > function MultiSelector( list_target, max ){


    Does the Opera error console display any errors caused from processing
    that file?

    > which defines the MultiSelector object. Way down toward the bottom of
    > the page is a short javascript block which invokes this object:
    >
    > <script type="text/javascript">
    > <!-- Create an instance of the multiSelector class, pass it
    > the output target and the max number of files -->


    Note that JavaScript comments are done with
    //comment
    or
    /*
    comment
    */
    but not with <!-- comment -->

    > var multi_selector = new
    > MultiSelector(document.getElementById('files_list'), 0);
    > <!-- Pass in the file element -->
    > multi_selector.addElement(document.getElementById('fname'));
    > </script>
    >
    > Opera gives this message:
    >
    > Reference to undefined variable: MultiSelector
    >
    > Why doesn't Opera know what this object is?


    Probably because it found an error processing that file.
    Post a URL and we can tell more.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 22, 2008
    #2
    1. Advertising

  3. Tim Slattery

    Tim Slattery Guest

    Martin Honnen <> wrote:

    >Tim Slattery wrote:
    >
    >> I include an external javascript file ("mutifile.js") in the head
    >> section of my HTML page. The first thing in this script is
    >>
    >> function MultiSelector( list_target, max ){

    >
    >Does the Opera error console display any errors caused from processing
    >that file?


    Only what I posted here: "Reference to undefined variable:
    MultiSelector". That's the only thing on the error console.
    >
    >> which defines the MultiSelector object. Way down toward the bottom of
    >> the page is a short javascript block which invokes this object:
    >>
    >> <script type="text/javascript">
    >> <!-- Create an instance of the multiSelector class, pass it
    >> the output target and the max number of files -->

    >
    >Note that JavaScript comments are done with
    > //comment
    >or
    > /*
    > comment
    > */
    >but not with <!-- comment -->
    >
    >> var multi_selector = new
    >> MultiSelector(document.getElementById('files_list'), 0);
    >> <!-- Pass in the file element -->
    >> multi_selector.addElement(document.getElementById('fname'));
    >> </script>
    >>
    >> Opera gives this message:
    >>
    >> Reference to undefined variable: MultiSelector
    >>
    >> Why doesn't Opera know what this object is?

    >
    >Probably because it found an error processing that file.
    >Post a URL and we can tell more.


    Unfortunately, its a restricted system.

    --
    Tim Slattery

    http://members.cox.net/slatteryt
    Tim Slattery, Jan 23, 2008
    #3
  4. Tim Slattery

    VK Guest

    On Jan 22, 8:34 pm, Tim Slattery <> wrote:
    > I've used a script provided by Stickman (http://www.the-stickman.com),
    > which allows a variable number of files to be uploaded from an HTML
    > page. In a nutshell, when a file is selected, it hides that <input
    > type="file"...> element, puts the name of the file selected in text on
    > the page, and creates a new <input...> element. A bit klunky, but it
    > works.
    >
    > I've now tested this on IE6, IE7, Firefox, Safari (3.0 for Windows, I
    > haven't got the Mac version to go yet), and they have no problem with
    > it. But Opera does.
    >
    > I include an external javascript file ("mutifile.js") in the head
    > section of my HTML page. The first thing in this script is
    >
    > function MultiSelector( list_target, max ){
    >
    > which defines the MultiSelector object. Way down toward the bottom of
    > the page is a short javascript block which invokes this object:
    >
    > <script type="text/javascript">
    > <!-- Create an instance of the multiSelector class, pass it
    > the output target and the max number of files -->
    > var multi_selector = new
    > MultiSelector(document.getElementById('files_list'), 0);
    > <!-- Pass in the file element -->
    > multi_selector.addElement(document.getElementById('fname'));
    > </script>
    >
    > Opera gives this message:
    >
    > Reference to undefined variable: MultiSelector
    >
    > Why doesn't Opera know what this object is?


    In the head script, you are not using defer flag? Like
    <script src="script.js" defer></script>
    If you do then remove it and see if any difference.

    Other option is with DOM methods - like getElementById - used before
    document load event. Theoretically the engine should send to hell any
    such attempts, practically the majority of modern browsers are still
    trying to do something useful but in different ways and with different
    reliability. Maybe Opera chocks on it but fails to report the error
    properly.

    Both options failed, the exact page content would be needed to help.
    VK, Jan 23, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Damien Cymbal
    Replies:
    2
    Views:
    913
    Jim Moe
    Mar 17, 2006
  2. Bob
    Replies:
    24
    Views:
    1,515
  3. Stefan Mueller
    Replies:
    7
    Views:
    124
  4. Steve Chapel
    Replies:
    15
    Views:
    230
  5. Jorge
    Replies:
    3
    Views:
    130
    Gregor Kofler
    Jul 2, 2008
Loading...

Share This Page