|
|
|
|
![]() ![]() |
Feb 17 2007, 12:48 AM
Post
#1
|
|
|
Member [ Level 2 ] Group: Members Posts: 71 Joined: 16-December 06 Member No.: 18,419 |
Hello,
I have started to try to create a JavaScript application (or rather, AJAX, but the JavaScript is the part I'm having trouble with). I have come across a roadblock, though. I try to load an external JavaScript file by editing the innerHTML of a div tag to contain <script src="URL" type="text/javascript"> (with a real URL). The problem is that it is not loading. I have used FireBug to check the dynamic HTML status, I get the following (with code removed): CODE <html> <head/> <body> <div id="status"/> <div id="main"/> <script type="text/javascript"> </script> <div id="scripts"> <!--START DYNAMIC JAVASCRIPT--> <script src="source/main_login.js" type="text/javascript"> </script> <!--END DYNAMIC JAVASCRIPT--> </div> <script src="source/main.js" type="text/javascript"> </script> </body> </html> I have done extensive testing and am sure that main_login is not loading. When I insert the relevant code into the actual file, it works fine. Is there anything I am doing wrong and/or is there a solution? Note: This could be related to the fact that FireBug does not update the dynamically added code when I change it, but that may just be a bug. I am also having a problem with inserting HTML into a <div> tag - my tags seem to close themselves, as in the following code. It seems quite possible that the two problems are related. CODE <div id="main"> <div id="main/login"/> <form onsubmit="java script:login(this);"/> <table/> User Name: <input type="text" name="usr_name"/> Password: <input type="password" name="usr_pass"/> <input type="submit" value="Log In"/> </div> (the table, and form should encompass the whole) This post has been edited by bluefish: Feb 17 2007, 03:07 AM |
|
|
|
Feb 17 2007, 02:10 AM
Post
#2
|
|
|
PESTICIDAL MANIAC Group: Members Posts: 626 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 |
I don't really like using innerHTML and prefer using DOM methods to manipulate the documents. With innerHTML, you don't need to encode HTML entities, you can simply pass the complete string, e.g. <script type="text/javascript">... When using the DOM you must create the elements, and append the data on them. Although it requires more work, it gives better understanding to your document creation, also not all browsers support innerHTML.
As with the automatic closing of each element, I can't explain that. Are you using a script you created yourself, or a script created by someone else? Cheers, MC |
|
|
|
Feb 17 2007, 03:07 AM
Post
#3
|
|
|
Member [ Level 2 ] Group: Members Posts: 71 Joined: 16-December 06 Member No.: 18,419 |
Thanks MC,
I solved the first problem by using DOM. I don't know what the original problem was, but it might have something to do with innerHTML not activating the script object. Anyways, it worked out without any real problems. As for the second problem, it was my fault for appending the lines of HTML separately, when I should have put them in a string and then put the whole string on. InnerHTML automatically closes unclosed tags when it's changed, so it could't tell that I intended to close it later. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 22nd November 2008 - 11:52 PM |