473,414 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Unusual behavior in function calls in java script

Hi,
I am dynamically including .js files on a button click. There is a segregated function to do the same. It doesnt seems to work well. If I put a alert tag in the includeJSFile function, it works well. Else it says init is not defined. Is there peculiarity in how function calls are terminated or something
I am attaching the code snippet below.
Expand|Select|Wrap|Line Numbers
  1. headTag.appendChild(imageScriptTag);         
  2.     includeJSFiles('js/image-slideshow.js','text/javascript');
  3.     includeJSFiles('OpenLayers-2.6/lib/OpenLayers.js','text/javascript');
  4.     includeJSFiles('OpenLayers-2.6/lib/Firebug/firebug.js','text/javascript');
  5.     includeJSFiles("js/mapStandaloneBox.js","text/javascript");    
  6.     includeJSFiles('js/dom-drag.js','text/javascript');    
  7.     init();
  8.     document.getElementById('GoVid').onclick=checkButtonCall;
  9.     checkButtonCall();
  10.     }
  11. }
  12. }
  13. function includeJSFiles(src,type) {
  14.     var headTag=document.getElementsByTagName('head')[0];
  15.     var scriptTag=document.createElement('script');    
  16.     scriptTag.src=src;
  17.     scriptTag.type=type;
  18.     headTag.appendChild(scriptTag);
  19.     return true;
  20.     //console.log(headTag.innerHTML);
  21. }
  22.  
Nov 20 '08 #1
4 2292
gits
5,390 Expert Mod 4TB
what does the init() method do? is it a function that relies on one of the included scripts before?

kind regards
Nov 20 '08 #2
what does the init() method do? is it a function that relies on one of the included scripts before?

kind regards
Thanks for reply

yep. init() relies on the openlayers script included above. How do I invoke Openlayers constructor. Including in head tag and loading seems to invoke that constructor but not the tag addition by later method.
Nov 20 '08 #3
gits
5,390 Expert Mod 4TB
i think the include of scripts that you do here is just an async process ... so you cannot rely on the code instantly. since you add the src-attrib this might start to load the script when you add it to the document and the init() method is called to early. you could poll and wait for all code that you want to use during the process ... you may use an interval and ask for something like ...

Expand|Select|Wrap|Line Numbers
  1. if (typeof init != 'undefined') {
  2.     init();
  3. }
kind regards
Nov 20 '08 #4
i think the include of scripts that you do here is just an async process ... so you cannot rely on the code instantly. since you add the src-attrib this might start to load the script when you add it to the document and the init() method is called to early. you could poll and wait for all code that you want to use during the process ... you may use an interval and ask for something like ...

Expand|Select|Wrap|Line Numbers
  1. if (typeof init != 'undefined') {
  2.     init();
  3. }
kind regards
yep. that sounds good. Actually, openlayers inturn loads a many other js files. Since its a async process, that happens separately and init has few components of those js file, hence it breaks. Thanks.
Nov 20 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Derek Basch | last post by:
Hello, *First question* If the syntax of spawnl is: spawnl(mode, path, ...) Why does everyone write it like:
4
by: DaKoadMunky | last post by:
<CODE> #include <iostream> using namespace std; int Foo(int x,int y) { int result = x; result*=y; result+=y;
3
by: Farooq Khan | last post by:
why does Response.Write in a method of code-beind class when called from inpage code (i.e in <%---%>), after creating object of that class, fails when called while it works perfectly ok while...
6
by: Kenneth | last post by:
Hi, function NewWindow(mypage, myname, w, h, scroll) { var winl = (screen.width - w) / 2; var wint = (screen.height - h) / 2; winprops =...
2
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and...
4
by: the.new.delboy | last post by:
Hi, I'm working on an application which requires some native calls to be made from Java. The calls work fine in one version of my code. I need to change the location of my native calls to a...
7
by: Mike Kent | last post by:
It's often useful for debugging to print something to stderr, and to route the error output to a file using '2>filename' on the command line. However, when I try that with a python script, all...
0
by: Michal Kwiatkowski | last post by:
I'm building a tool to trace all function calls using sys.settrace function from the standard library. One of the awkward behaviors of this facility is that the class definitions are reported as...
4
by: Newbie | last post by:
Hello I need to enter a string of the form abc (a string of characters followed by EOF) #include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX 100 int main(void) {
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.