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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Externally referenced Script Problem

    hi I been trying to get my web page to work with an externally referenced script. Here is a part of the page:

    <script src="combobox.js">
    var ComboBox;
    function bodyOnload1()
    {
    <!-- cbJSMainFunc() is found in combobox.js-->
    ComboBox = new cbJSMainFunc("ComboBoxID", "cbGID");
    }
    var temp = new bodyOnload1();
    </script>


    when I try to use the function bodyOnload1() upon OnLoad event they tell me "Object expected"

    <body onload = "bodyOnload1();" >

    I have tried creating an object with above function but the web page cant dected the variable(undefined error).

    <body onload = "temp.bodyOnload1();" >

    Can anyone help?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    paris, france
    Posts
    1,216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it might have something to do with the script you called externally. it might be a problem with that. post it here so wes can have a look at it.
    photoshop too expensive? use the GIMP! www.gimp.org

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Atlanta, GA.
    Posts
    313
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It sounds like you are using a cross browser API. Possibly
    Cross Browser Script.

    If so you may need to link to other external files. E.g. :-
    <script language="Javascript1.2" src="utility.js"></script>
    <script language="Javascript1.2" src="cbscript.js"></script>

    (Unless combobox.js has had all the code copied into it from the other files)

    Can you provide a link to where you obtained the script. It may have more usefull information.
    The answer does not come from thinking outside the box, it comes from realizing the truth :-
    "There Is No Box". [JavaScript Gadgets'n'Gizmos][JavaScript-FX]

  • #4
    New Coder
    Join Date
    Jun 2002
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi junkpile,

    your problem entirely derives (provided the constructor function is actually included in the external js) from the fact you can't safely nest scripts in a script tag which carries a SRC property: you can nest new scripts/functions only in script tags that do not carry ani SRC attribute.
    Therefore:

    <script src="foo.js"></script> EMPTY set
    <script> myFunc=new fooScript() </script>

    Try, that way should work smoothly.

    ciao
    Alberto http://www.unitedscripters.com/

  • #5
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    Hi TrueLies,

    When I did something like this, the broswer tells me that fooScript is undefined.

    <script src="foo.js"></script> EMPTY set
    <script> myFunc=new fooScript() </script>


    By the way I thought that JavaScript didn't need to have a constructor like Java. If there is a need for a constructor, where and how should it be implemented?

    Thanks

  • #6
    New Coder
    Join Date
    Jun 2002
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    your expression that I reinterpreted as
    myFunc=new fooScript()

    IS a constructor: I am not calling in or suggesting to you to use a constructor: i'm simply saying you're *already* using it, which is legitimate.
    So: if you still have problems getting a "fooScript is undefined", this means what it says: apparently, you have not defined the function that performs as a constructor.

    Your code is:
    var ComboBox;
    function bodyOnload1()
    {
    <!-- cbJSMainFunc() is found in combobox.js-->
    ComboBox = new cbJSMainFunc("ComboBoxID", "cbGID");
    /*CALL TO A CONSTRUCTOR: must be previously defined*/

    }
    var temp = new bodyOnload1();

    /*CALL TO A ACONSTRUCTOR: it IS defined just above, but it has a constructor within itself: is the latter defined?*/

    By your code, it is implied somewhere either in the external file or in your script there *must* be a snippet whose edges are like this:

    function fooScript(){/*stuff*/}

    So problems could be:

    1) such function [ or cbJSMainFunc() ] has never been defined: you cannot call the "new" operator on a function that doesn't exists: it doesn't create the function if it calls in a function name: it creates a new *instance* object molded upon that function: but you do need the function.

    2) script tag pointing to an external source should be empty.

    3) the external script (or inline script) which holds the definition of the construtor (fooScript function in our case) must be loaded prior to whatever initialization of a new instance of that constructor. (basically this amounts to this: if your fooScrtipt is on external source and you first load the script that call in the constructor and AFTER the external file with the constructor, the attempt to build the new instance would fail since javaScript is interpeted not compiled -as the old saying goes!- and only objects that have already been loaded in the browser chache can be triggered without yielding errors. Also, other functions that might call in prematurely an object not loaded yet from within some remote code bit nested deep inside them, are obviously fit to generate an error: be sure your constructors are cahced before everything else)

    I hope this helps

    ciao

    PS also:
    ---quote---
    var temp = new bodyOnload1();
    </script>
    when I try to use the function bodyOnload1() upon OnLoad event they tell me "Object expected"
    <body onload = "bodyOnload1();" >
    ---quote---

    Maybe there is a possible problem here: by calling the
    var temp = new bodyOnload1();
    you're already executing a function
    if it works then, no reason it shouldn't when you call it again by onLoad, unless... UNless it is a constructor or not: for if it is a constructor, its internal code demands it to be used ALWAYS by keyword NEW, if it is NOT, keyword NEW should be avoided (the former statement is quite correct, the latter not entirely true, but I'm trying to understand what your functions might look like...).

    I think you'd post more code! A possible suspect is: you cannot call in as a normal static function a function whose internal shape is abundant with... "this." keywords...!
    ciao
    Last edited by TrueLies; 06-22-2002 at 08:54 PM.
    Alberto http://www.unitedscripters.com/

  • #7
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help me please :(

    I am sorry for having a lot of questions but the attachment has the files that I have been working on.

    Basically, all I want if you read through "Combobox.js" is to allow anyone who view the page to be able to enter values into a combo box like the ComboBox control in VB. On top of that be able to capture the entered value.

    The attached files is a sample of my problems that occur on my actual web page.

    Could someone help point out the problem please?
    Attached Files Attached Files


  •  

    Posting Permissions

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