Results 1 to 5 of 5

Thread: Call Script Dynamically

  1. #1
    Join Date
    Nov 2008
    Posts
    1,221

    Call Script Dynamically

    I call a JavaScript script dynamically. Only worries, it is well known in the div in which I say but do not load in the div in which it is called at the bottom of my page.

    Here is my code

    PHP Code:
    <div id='test'>
    function 
    calls_js() {
     var 
    newscript document.createElement('script');
      
    newscript.type  'text/javascript';
      
    newscript.onload  onLoad;
      
    newscript.src   'http://mysite.com/script.php?code=' myvariable;
     var 
    head document.getElementById('test');
     
    //var head = document.getElementsByTagName('head')[0]; 
      
    head.appendChild(newscript);
    }
    function 
    onLoad() {
     
    document.close();
    }
    calls_js();
    </
    div
    result in my code:
    PHP Code:
    <div id='test'><script type='text/javascript' src='http://mysite.com/script.php?code=145228'></script></div
    but the result of the script appears at the end of my site and not in the div 'test'. I think it's linked to the onload event but I can not find a solution.

  2. #2
    Join Date
    May 2008
    Posts
    3,971

    Re: Call Script Dynamically

    1. Do not put the script in <div> ...</ div>
    A division is made to contain a text or an image, but not to contain a piece of JavaScript, even if not explicitly forbidden.

    2. Put the script in the <head> ...</ head>
    The normal place for a script in the header of the page.

    3. Put the call to a JavaScript function, for example call_js (); in the management of an event.
    For example, in the onclick of a button.

  3. #3
    Join Date
    Nov 2008
    Posts
    1,221

    Re: Call Script Dynamically

    Thank you very much for your reply.

    my concerns:
    l1) the script returns an image and I must be able to control its position so the launch in the head yes but after the result of this script so the image, or how the position I want is all my worries!

    2) this script must be run at the opening of the page so the onclick I can not

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Call Script Dynamically

    but the result of the script appears at the end of my site and not in the div 'test'.
    It depends only (in advance) of what the script called. The fact to call anywhere, does not required that will display the "result" where it is ...

  5. #5
    Join Date
    Nov 2008
    Posts
    1,221

    Re: Call Script Dynamically

    The script returns an image:
    if I do:
    PHP Code:
    <div id='test'><script type='text/javascript' src='http://mysite.com/script.php?value=45147'></script
    </
    div
    No worries, the image appears in the div, or so I want it to be. Now, if I call the script dynamically (no choice because I have a JavaScript variable in the src), I have in the source

    PHP Code:
    <div id='test'><script type='text/javascript' src='http://mysite.com/script.php?value=45147'></script
    </
    div
    but the image appears at the end of my site (just before closing the body)

Similar Threads

  1. Failed to run install script error in Call of Duty 6
    By Jaimenacho in forum Video Games
    Replies: 4
    Last Post: 15-02-2010, 02:12 PM
  2. How can I call VBA method dynamically?
    By opaper in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 09:25 AM
  3. How to call perl script from Python?
    By Jhonwho in forum Software Development
    Replies: 3
    Last Post: 23-07-2009, 09:59 PM
  4. how to call or execute mySql script in php?
    By Quattro in forum Software Development
    Replies: 3
    Last Post: 03-07-2009, 11:53 PM
  5. Several. Msc window from a batch / script call?
    By Stephanatic in forum Technology & Internet
    Replies: 2
    Last Post: 26-11-2008, 05:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,252,822.62266 seconds with 16 queries