473,729 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unusual behavior in function calls in java script

17 New Member
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 2317
gits
5,390 Recognized Expert Moderator Expert
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
rakesh19
17 New Member
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 Recognized Expert Moderator Expert
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
rakesh19
17 New Member
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
3393
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
2651
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
1700
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 calling the same method same way except for creating object instead directly calling the method? i get this when trying to do that:- ************************************************** Response is not available in this context. Description: An...
6
1639
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 = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scro llbars='+scroll+',resizable=0' win = window.open(mypage, myname, winprops) if (parseInt(navigator.appVersion) >= 4) {
2
3387
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 place it in the last cell of each row that I create dynamically using DOM methods. Everything is working well (that is, just like the original example) except for something related to the function behind my link. The link simply calls a function...
4
4895
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 different file but when I move them to another native file I receive the following error. I've included all .h includes and path locations (LD_LIBRARY_PATH) and the build script contains the libraries required to run. The strange thing: I removed...
7
2045
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 prompt output from raw_input goes to stderr. Consider the following test program: === Start test.py === import sys
0
1170
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 'call' events. Since I don't want to catch class definitions, only function calls, I'm looking for a way to differentiate between those two. So far I have only vague clues about how to do that. At the bottom of this mail is a simple script that...
4
5071
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
8923
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9428
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9285
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9151
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8155
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6025
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.