Document.write and Validation

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Document.write and Validation

Post by Shendemiar »

I have this code:

Code: Select all

157: <!-- JavaScript -->
158:   <SCRIPT type="text/javascript">
159:     <!--

SNIP

184:       document.write('<DIV CLASS="overflow" STYLE="HEIGHT:'+y+'px;">');
185:     -->
186:   </SCRIPT>
187: <!-- JavaScript -->
And validators keep complaining that the <DIV> was not opened.

I know this is javesript basics, but how could i make that way that only the STYLE.. and so forth get's written by JS, and the ">" is again written by php

Somehing like:
echo "<DIV CLASS=\"overflow\" document.write('STYLE=\"HEIGHT:''+y+'px;');>";

Is there a way for some browser to see the "result source", like how it would seem after the document write's have been done?
Last edited by Shendemiar on Tue Jan 04, 2005 2:15 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why not just have javascript update the style information of that tag?
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

feyd wrote:why not just have javascript update the style information of that tag?
Please be patient with me... i know nothing of javascript. How would i do what you suggested?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<div class="overflow" id="hookMe">
...
function updateHeight( id, newHeight )
&#123;
  var obj = document.getElementById ? document.getElementById( id ) : document.all&#1111; id ];
  if( obj == null ) return;
  obj.style.height = newHeight + 'px';
&#125;
...
updateHeight( 'hookMe', 20 );
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

I understand what it sould do and i like it. Anyway, i cant get it to work.

So, how could i debug what js does? Any tools you could recommend me. With just a browser there's not much indicators what happens.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sure works for me in IE6 SP2, Firefox 1:

Code: Select all

<html>
	<head>
		<title>example</title>
		<style>
			.overflow
			&#123;
				background-color: #000;
				color: #FFF;
				text-align: center;
			&#125;
		</style>
		<script language="Javascript">
			function updateHeight( id, newHeight )
			&#123;
				var obj = document.getElementById ? document.getElementById( id ) : document.all&#1111; id ];
				if( obj == null ) return;
				obj.style.height = newHeight + 'px';
			&#125;
		</script>
	</head>
	<body>
		<div class="overflow" id="hookMe">
			example<br />
		</div>
		<a href="javascript: updateHeight('hookMe', 300);">300</a><br>
		<a href="javascript: updateHeight('hookMe', 200);">200</a><br>
		<a href="javascript: updateHeight('hookMe', 100);">100</a><br>
	</body>
</html>
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

No!!!

I wasn't critizising your script. I know it's allright.

I just said i cant make it work (on my complex page) And as i want to make it work myself, i asked if there's any tools to help javascript debugging/testing that would output something additionl but just the result?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there are some debugging tools out there, although I don't know of any off-hand. What I do for debugging is fairly simple: I place lots of alerts or debug prints to a secondary window (created by the script when in debug mode)
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

feyd wrote:there are some debugging tools out there, although I don't know of any off-hand. What I do for debugging is fairly simple: I place lots of alerts or debug prints to a secondary window (created by the script when in debug mode)
Okay, that eases my mind some. If you say there isnt usefull tools, i must not worry ;)

Got it working, i had the Div to be updated later on the code than the update call ;)

Thanks again!
Post Reply