Page 1 of 1
Document.write and Validation
Posted: Tue Jan 04, 2005 2:03 pm
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?
Posted: Tue Jan 04, 2005 2:14 pm
by feyd
why not just have javascript update the style information of that tag?
Posted: Tue Jan 04, 2005 2:20 pm
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?
Posted: Tue Jan 04, 2005 2:27 pm
by feyd
Code: Select all
<div class="overflow" id="hookMe">
...
function updateHeight( id, newHeight )
{
var obj = document.getElementById ? document.getElementById( id ) : document.allї id ];
if( obj == null ) return;
obj.style.height = newHeight + 'px';
}
...
updateHeight( 'hookMe', 20 );
Posted: Tue Jan 04, 2005 3:04 pm
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.
Posted: Tue Jan 04, 2005 3:20 pm
by feyd
sure works for me in IE6 SP2, Firefox 1:
Code: Select all
<html>
<head>
<title>example</title>
<style>
.overflow
{
background-color: #000;
color: #FFF;
text-align: center;
}
</style>
<script language="Javascript">
function updateHeight( id, newHeight )
{
var obj = document.getElementById ? document.getElementById( id ) : document.allї id ];
if( obj == null ) return;
obj.style.height = newHeight + 'px';
}
</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>
Posted: Tue Jan 04, 2005 3:38 pm
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?
Posted: Tue Jan 04, 2005 4:01 pm
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)
Posted: Tue Jan 04, 2005 4:05 pm
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!