473,666 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't access function inside dynamically added script source

Hi,

Following the discussion that can be found here:
http://groups.google.com/group/comp....9da813c8527282

I modified mine and was trying to launch an alert message inside the
dynamically added script [data.js].

My sample codes
=============== =============== =============== ===
[data.js]

var remoteValue = 'Blah blah';
alert('File loaded... ' + remoteValue);

function alertME()
{
alert('alertME in data.js');
}
[HTML]

<a href="#" onclick="addScr ipt('data.js'); ">START</a>

<script type="text/javascript">
var x = 'im blank';
alert(x);
function addButton()
{
var oButton = document.create Element('input' );
oButton.value = 'Add script element';
oButton.setAttr ibute("onclick" , "alertME(); ");
oButton.type = 'button';
document.body.a ppendChild(oBut ton);
}

function getValues(x)
{
alert(x); // Shows 'removeValue'
setTimeout('ale rt('+x+')',0); // Shows 'Blah blah'
}

function addScript(uri)
{
var oScript = document.create Element('script ');
oScript.src = uri;
//var head = document.getEle mentsByTagName( 'head')[0];
//head.appendChil d(oScript);
document.body.a ppendChild(oScr ipt); //-head or body, both works
in Firefox 2.0.0.4

addButton();
}
</script>

The alert messages for 'x' appeared correctly. But Firebug return this
error: alertME is not defined, and 'alertME in data.js' never appear.

Is this a limitation in Javascript? Or Did I miss out on something
important?

Your suggestion are trully appreciated.
Thanks.

Jun 20 '07 #1
2 1948

try this instead

oButton.onclick = function() {alertME();};

Jun 20 '07 #2
On Jun 20, 1:59 pm, Pete <peter.gal...@g mail.comwrote:
try this instead

oButton.onclick = function() {alertME();};
Thanks for your reply.

I have tried that line of code before and strangely, it didn't work.
That's why I replaced it with oButton.setAttr ibute("onclick" ,
"alertME(); ");

The above code does actually work. I missplaced the correct "data.js"
inside another folder. After placing it inside the correct folder, it
works like a charm.

Thanks for your time.

Jun 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3462
by: christine.nguyen | last post by:
Hello all, I have a page called test.html. Within test.html I have an iframe whose source is mypage.html. When mypage.html loads, it dynamically creates a javascript element which contains a function called doIt() and attaches it to the parent page, which is test.html. I have a button on test.html that then needs to call the dynamically attached doIt() function. I got this to work fine on Firefox and Opera on the Mac, but Safari is...
4
7447
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the placeholder,the user selects the required tags from the dropdownlists (if 5 Xml tags,then 5 dropdownlists each containing 5 xml tags) and now the btnSave button is selected which extracts the user selection form the dropdownlists.
3
1492
by: steve_h | last post by:
I think the subject says it all, but just in case: I know that I can call my own methods during an XSL transformation using <xsl:value-of select="myObject.someMethod(arg1)" /> having done something like: dim xslTrans as System.Xml.Xsl.Xsltransform
6
4868
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
1
6502
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to java class which creates a xml file based on values entered in dynamic jsp page. Now i want to read all those values entered to xml in my other jsp page. I am able to call values from file in my jsp page. But as dynamic values can be any in no...
37
3926
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as a function
2
2590
by: aric.bills | last post by:
Hello all, I'm a novice Javascript programmer, and I'm having browser compatability issues regarding dynamic generation of tables. The following content generates "hello" in Firefox 1.5, but just a blank page in IE 6. Can anybody tell me what I should change to make IE happy? Even better, is there any kind of tutorial out there on dynamically generating tables? Many thanks,
8
3102
by: Samik R. | last post by:
Hello, I am using the innerHTML property of a div placeholder to update the contents, and the HTML is provided from a perl script on the server side. The perl script gets called through AJAX when I press a button in the first page. The returned HTML in the div has another button, which, when pressed, should call the same perl script again. Think of the program as some sort of wizard. The problem is, this works perfectly as expected in FF...
4
4576
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
0
8440
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
8352
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
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
8780
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...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6189
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
5661
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
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.