Jump to content


Creating HTML with Js


2 replies to this topic

#1 Mike87

    Young Padawan

  • Members
  • Pip
  • 4 posts
  • Location:Holland

Posted 27 December 2006 - 08:41 PM

Hello,

I'm working on a small project at the moment and I tried something but afcourse, it did not work. :)

My idea was:
With a onClick event a 'div element' covers the whole website so that all the other clickable stuff doesn't work anymore and a little centered div apears with a loading-img and some text that de content is beeing loaded.

The JS-code that I have come up with, with a few eye's looking at other script:
function Message() //Titel, Message, Loading
		{
			
			document.getElementById('fullscreen').style.visibility = 'visible';
			
			var objContainer = document.createElement("div");
				objContainer.setAttribute('id', 'objContainer');
				
			var objTitel = document.createElement("div");
				objTitel.setAttribute('id', 'objTitel');
				objTitel.appendChild('Loading...');
				objContainer.appendChild(objTitel);
				
			var objContent = document.createElement("div");
				objContent.setAttribute('id', 'objContent');
				objTitel.appendChild('Please wait longer!!!!');
				objContainer.appendChild(objContent);
			
			//if ( Loading )  
			//	{
					var objLoading = document.createElement("div");
						objLoading.setAttribute('id', 'objLoading');
						objTitel.appendChild('<img src="Projects/Images/Loading.gif" />');
						objContainer.appendChild(objLoading);
			//	}
				
			var objFooter = document.createElement("div");
				objFooter.setAttribute('id', 'objFooter');
				objContainer.appendChild(objFooter);
			
		}

With the BugConsole in FireFox I found 1 error:

Quote

Error: uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://localhost/tmpjs.js :: Message :: line 15" data: no]

On line 15 you will find:
objTitel.appendChild('Loading...');

But I do not understand the problem with this line of code.
Could someone help my out with this? :P

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 28 December 2006 - 02:28 PM

I would recommend checking out quirksmode.org for more help on this. More specificially, the following page: http://www.quirksmod...tro.html#change

The last time i dealt with JS and DOM, i only played around with what you're doing for about a day, so i don't remember much. I just know 2 things. 1, i found something easier than the DOM. 2, you're not passing the right argument.

appendChild takes a JS object as a paramater, not a string.

So, to simplify things (rather than fix what you did), try this:
function Message(){
	var fullscreen = document.getElementById('fullscreen');
	fullscreen.style.visibility = 'visible';
	var loadDiv = '<div id="objContainer">
	<div id="objTitle">Loading...</div>
	<div id="objContent">Please wait longer!!!!</div>';

	//if ( Loading ){
		loadDiv += '<div id="objLoading"><img src="Projects/Images/Loading.gif" /></div>';
	//}
				
	loadDiv += '<div id="objFooter"></div>';
	fullscreen.innerHTML = loadDiv;
}
That should work, i haven't tested it, but you should see some slightly better results.

p.s. I don't know if you knew this or not, but you never would have seen the loading div, it was never appended to "fullscreen." You also spelt "title" wrong :hi:

#3 Mike87

    Young Padawan

  • Members
  • Pip
  • 4 posts
  • Location:Holland

Posted 29 December 2006 - 08:44 AM

The problem is solved.
I also forgot to assign the new HTML to the BODY element.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users