Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Problems With Dynamically Loading Javascript, As well as dynamically inserting HTML
bluefish
post Feb 17 2007, 12:48 AM
Post #1


Member [ Level 2 ]
Group Icon

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"/>
&lt;script type="text/javascript">

</script>
<div id="scripts">
<!--START DYNAMIC JAVASCRIPT-->
&lt;script src="source/main_login.js" type="text/javascript">

</script>
<!--END DYNAMIC JAVASCRIPT-->
</div>
&lt;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
Go to the top of the page
 
+Quote Post
mastercomputers
post Feb 17 2007, 02:10 AM
Post #2


PESTICIDAL MANIAC
Group Icon

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
Go to the top of the page
 
+Quote Post
bluefish
post Feb 17 2007, 03:07 AM
Post #3


Member [ Level 2 ]
Group Icon

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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Converting HTML over to XHTML(13)
  2. Nero Problems(32)
  3. Rakion Problems.(2)
  4. JavaScript: Hide And Show Any Element With CSS(6)
  5. Problems Installing Vista(14)
  6. Screensaver Problems(11)
  7. Converting PSD To HTML(11)
  8. Loading External Actionscript(4)
  9. Office 2007 Document Problems(14)
  10. Need A Javascript To Enable / Disable Buttons(2)
  11. Html Basic Tutorial(9)
  12. Internet Connection Sharing Problems(2)
  13. Gimp: Saving As... Issues(3)
  14. Image Problems With Windows 2000(10)
  15. How To: Display A Members/user List.(3)
  1. Wamp Server Problems(5)
  2. Indentation In Html(4)
  3. Joomla Template Kit Extension For Nvu/composer(3)
  4. What You Need Before You Can Create A Text-based Game..(7)
  5. Checking Without Loading(1)
  6. Basic Html Tutorial(1)
  7. Problems With New Computer(10)
  8. Problems Using Usb Devices(7)
  9. Good Books For Html And Css Beginners(1)
  10. 12 Javascript Image Galleries(0)
  11. How To Design The Popup Menu Item Using Javascript(1)(0)
  12. How To Design The Popup Menu Item Using Javascript(2)(0)
  13. Email Server / Cpanel Problems(1)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 11:52 PM