Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 11-04-2009
Member
 
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.
Reply With Quote
  #2  
Old 11-04-2009
Member
 
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.
Reply With Quote
  #3  
Old 11-04-2009
Member
 
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
Reply With Quote
  #4  
Old 11-04-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Call Script Dynamically

Quote:
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 ...
Reply With Quote
  #5  
Old 11-04-2009
Member
 
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)
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 03:40 AM.