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 9 of 9
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What's wrong with this?

    Hi,

    I'm strugling to get a script runwithin a script. As an example I made a simple script and put it in a function called SayHello. The function is supposed to run the script right?

    Here is simple code:

    <html>
    <head>

    <script type="text/javascript">
    <!--
    function SayHello( )
    {
    <script>
    document.write("Hello!");
    </script>
    }
    // -->
    </script>

    </head>
    <body>

    <script type="text/javascript">
    <!--
    SayHello( );
    // -->
    </script>

    </body>
    </html>


    I can't see why it's not working, - anyone?

  • #2
    New Coder
    Join Date
    May 2005
    Location
    Alabama
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    remove the <script> tags in the code, it'll give u an error because u r mixing up HTML with JavaScript incorrectly... try this:

    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    <!--
    function SayHello()
    {
    document.write("Hello!");
    }
    // -->
    </script>
    
    </head>
    <body>
    
    <script type="text/javascript">
    <!--
    SayHello();
    // -->
    </script>
    
    </body>
    </html>

  • #3
    Registered User
    Join Date
    Dec 2004
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi jshl_wiz, you must have missed what I said but that's not what I'm trying to do. I want the SayHello function to run a separate script - not a statement within it's own script.

  • #4
    New Coder
    Join Date
    May 2005
    Location
    Alabama
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, let me see if i understand, you want to write a script WITHIN another script, so you would have to do something like:

    <script>
    <!--
    function sayHello(){
    document.write("<script>");
    document.write("document.write('Hello!');");
    document.write("</script>");
    }
    //-->
    </script>
    </head>
    <body>
    <script>
    <!--
    sayHello();
    //-->
    </script>

    Are we in the same page now??

  • #5
    Registered User
    Join Date
    Dec 2004
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great thanks a lot. The first time some one gave me a straigh answer for this.

    Now what if I wanted the function to write an external file like:

    Code:
    <script type="text/javascript" src="http://website.com/file.js'><\/script>
    Sorry, I'm a newbie. I really appreciate the help.
    Last edited by ebay258; 05-26-2005 at 09:05 PM.

  • #6
    Registered User
    Join Date
    Dec 2004
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    bump!?

  • #7
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ebay258
    Great thanks a lot. The first time some one gave me a straigh answer for this.

    Now what if I wanted the function to write an external file like:

    Code:
    <script type="text/javascript" src="http://website.com/file.js'><\/script>
    Sorry, I'm a newbie. I really appreciate the help.

    <script>
    <!--
    function sayHello(){
    document.write("<script type='text/javascript' src='");
    document.write("http://website.com/file.js");
    document.write("'><\/script>");
    }
    //-->
    </script>
    </head>
    <body>
    <script>
    <!--
    sayHello();
    //-->
    </script>
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #8
    New Coder
    Join Date
    May 2005
    Location
    Alabama
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    don't really know if that one's possible... if your purpose is to save space you could do the whole function with the bunch of "document.write"'s in a separate JS file and then call it from your page.

  • #9
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please read this post.

    It will awnser all of your questions.

    Include a javascript file in another javascript
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<


  •  

    Posting Permissions

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