473,699 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Newbie Javascript Issue

1 New Member
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 1176
acoder
16,027 Recognized Expert Moderator MVP
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
1560
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. I need to run the 'submit' method on a Javascript on a page - but I need to do it without a browser. I can handle all the socket code, that's not the issue, the issue is what command I need to send. I should be able to hit the page and issue...
6
1345
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 suitable for the web since > without JavaScript it doesn't work at all and whilst I've stuck to > standards, it will be intolerant of some (particularly older) browsers > - but it is a bit of fun trying to do some of this stuff and create > ...
6
2578
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 entities here i wasn't 100% sure where to place it. Here is the background on the issue: I have a XML tag that is located in multiple places and multiple documents that has a structure of: <LINK ID="para0001">LINK TEXT</LINK> This tag...
33
19163
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 have a look-up table of latitude and longitude against locale, and then use the locale of the browser... But going through the documentation I can't find any reliable way of getting the locale in JavaScript. Am I missing something, or is this...
5
1780
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 some difficulties to make my code perfect. Yeah, I made it, by the help of the generous Google, it goes like this: ------------------------------My code Starts-------------------------------
13
1685
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 href="JavaScript:functionName(object);">Click me</a> Somehow it calls toString for the object and rather than it being processed as an object, it is processed as a string. Details: I'm trying to build a documentation UI (using VBA plugin mztools) and the objects I...
44
1675
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 reading JavaScript books until they've written some HTML and CSS. You need it _VERY_ rarely. Using it without a foundation of good HTML understanding leads to trouble. Few people can learn both from scratch simultaneously, so it's useful to really...
5
1397
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 get a long skinny button that extends to the right side of the browser. This does not appear to happen with other controls. Any idea why it happens to the button? Here is how the button looks in source code:
3
1288
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 form be submitted when I click on a href link. Currently it appears that the page reloads - but nothing actually is submitted. here is a demo code,,, is it something in the head?
0
8617
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
9174
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
9035
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
7751
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
6534
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
5875
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
4376
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
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
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.