473,387 Members | 2,436 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,387 software developers and data experts.

Newbie Javascript Issue

1
Hi all - can someone please point me in the right direction. I have pages that launch their javascript components fine if the page is loaded on its own. But when the page is loaded AJAX the javascript does not fire. An example is this simple web page:

[HTML]<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
alert("Hello World")
</script>
</body>
</html>[/HTML]

When called on it's own, I get a "hello world" alert.

When I load this page via AJAX into a div, the alert is not displayed.

I've written many pages which are dependent upon javascript which work fine until called by AJAX. I'm guessing this is simple but I'm missing a key ingredient here.

Thanks in advance for your help.
Apr 17 '08 #1
1 1162
acoder
16,027 Expert Mod 8TB
Yes, the key ingredient is that the JavaScript won't run like that.

There's two ways, either use eval (the quick, dirty way);

or dynamically add the script to the parent page, e.g.
Expand|Select|Wrap|Line Numbers
  1. var script = document.createElement("script");
  2. script.type="text/javascript";
  3. script.appendChild(document.createTextNode(theJScode));
  4. document.getElementsByTagName("head")[0].appendChild(script);
Apr 17 '08 #2

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

Similar topics

1
by: Nathan DeBardeleben | last post by:
This may seem wierd, and I know someone asked this question before but was told they were doing it the hard way. Unlike them, I do not have shell access to the machine where this javascript runs....
6
by: TJ | last post by:
Hello All, I posted a question a few days ago entitled "Select element with no selected options". Over the course of the discussion, RobG wrote: > This is just an example, it is not really...
6
by: kenundrum | last post by:
Hey all, I am having an issue with XML/XSLT and JavaScript in my ASP.NET page that I am creating. I first want to apologize if i placed this in the wrong category. Since there were three different...
33
by: Simon Brooke | last post by:
I'm working on a system which uses Google maps. I want the user to see a map of more or less where (s)he is in the world when (s)he first comes to the system. So the obvious thing seemed to be to...
5
by: mattmao | last post by:
Greetings everyone. The Newbie is coming back from uni... I knew making a good form validation JavaScript would be a piece of cake for you guys, but as a novice programmer as me, I still find...
13
by: paragpdoke | last post by:
Hello Everyone. Merry Christmas to all ! I'm a JavaScript newbie (and new to thescripts.com too). And I have problems in working with objects in JavaScript. The problem: <a...
44
by: Andy Dingley | last post by:
On 15 May, 04:55, Prisoner at War <prisoner_at_...@yahoo.comwrote: Or in another universe, where things are understood and site code is stable and reliable, beginners don't even think about...
5
by: Dave | last post by:
I am new to Visual Web Developer 2005 Expres. I am using absolute positioning and every time I add a button control to my web form its width extends all the way to the edge of the page. IOW I...
3
by: trfilmographer | last post by:
Hi fellow web developers! I have a little problem due to my lack of javascript / web developing skills... Basically I have a form embedded in a table. WHat I would like to do, is have the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...

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.