Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Javascript DOM problem when using certain Doctype - see example
Old 02-03-2007, 04:51 PM Javascript DOM problem when using certain Doctype - see example
Experienced Talker

Posts: 33
Trades: 0
Hi there

I am attempting to make a DIV resize automatically using Javascript.
I have written the code and it works in IE7, but not in Firefox.
Removing the Doctype enables it to run in FF.
I validated the code and it passed.

Here it is in action: http://www.realbabyguide.co.uk/div%20heights.html

Any ideas which Doctype to use. I have tried every one!
Thanks

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html>
<head>
<title>A Test</title>
<style type="text/css">
 body
 {
 background-color:#00CCFF;
 }
 
 .outer
 {
 font-size: 16px;
 background-color:#00CC00;
 padding: 10px;
 width: 100%;
 border-width: 1px;
 border-style: solid;
 border-color: #cc0000;
 }
 #inner
 {
 font-size: 16px;
 background-color:#CC6633;
 padding: 10px;
 width: 50%;
 border-width: 1px;
 border-style: solid;
 border-color: #cc0000;
 }
 
</style>
 
</head>
<body>
<script language="javascript" type="text/javascript">
function getOff()
{
 x = document.getElementById('inner');
 return x.offsetHeight;
 }
function changeOff(amount)
{
 amount = 600-getOff();
 var y = getOff();
 x.style.height = y + amount;
}
</script>
 
<div class="outer">
 <div id="inner">
 
   <h1>This script resizes my "inner" DIV height to 600px - the current height.</h1>
 
   <p>However, although it works in IE7 (haven't tried other IE versions), it will not work in Firefox (2.0.0.1).<br />
   Removing the Doctype enables it to work in Firefox, but screws up IE7 as it renders the page in Quirks mode.<br />
   The page    
   <a href="<A href="http://validator.w3.org/check?uri=http%3A%2F%2Fwww.realbabyguide.co.uk%2Fdiv%2520heights.html">validates.</a">http://validator.w3.org/check?uri=http%3A%2F%2Fwww.realbabyguide.co.uk%2Fdiv%2520heights.html">validates.</a>
   </a> 
   <br />
   Any ideas? 
   </p>
 
 </div><!-- Close inner DIV -->
 
</div><!-- Close outer DIV -->
<a href="javascript:changeOff()">Click here and the DIV should resize</a>
</body>
</html>
monkey64 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-05-2007, 12:54 AM Re: Javascript DOM problem when using certain Doctype - see example
saadatshah's Avatar
Extreme Talker

Posts: 215
Name: Syed Saadat Ali
Location: Lahore, Pakistan
Trades: 0
Read these:

http://www.w3.org/TR/html4/sgml/dtd.html

http://www.htmlhelp.com/tools/validator/doctype.html

and figure out the right doctype for you. Hope it helps
__________________
- -- --- ---- ----- ------ ------- ---------------
If you have knowledge, let others light their candles in it.

Last edited by saadatshah; 02-05-2007 at 12:54 AM.. Reason: Link added
saadatshah is offline
Reply With Quote
View Public Profile Visit saadatshah's homepage!
 
Old 02-05-2007, 08:11 AM Re: Javascript DOM problem when using certain Doctype - see example
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
Does the page validate when using the XHTML Doctype?

I noticed the line
Code:
   <a href="<A href="http://validator.w3.org/check?uri=http%3A%2F%2Fwww.realbabyguide.co.uk%2Fdiv%2520heights.html">validates.</a">http://validator.w3.org/check?uri=http%3A%2F%2Fwww.realbabyguide.co.uk%2Fdiv%2520heights.html">validates.</a>
   </a>
in your post.

OTOH, guessing that the posting is contrived, and the real page correct (your link gave me a 404) I think you may be having problems with the offsetheight prop.
Take a look at the following for some more info:
http://www.killersites.com/mvnforum/...ad?thread=4063
willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 02-05-2007, 08:58 AM Re: Javascript DOM problem when using certain Doctype - see example
Skilled Talker

Posts: 96
Name: Tudor Barbu
Trades: 0
Problem solved here: http://www.webmaster-talk.com/html-f...efox-look.html
__________________

Please login or register to view this content. Registration is FREE
Tudor.b is offline
Reply With Quote
View Public Profile Visit Tudor.b's homepage!
 
Old 02-05-2007, 09:07 AM Re: Javascript DOM problem when using certain Doctype - see example
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by monkey64 View Post
Code:
 x.style.height = y + amount;
Specify the units.
Code:
x.style.height = y + amount + 'px';
and the link should be written:
Code:
<a href="#" onclick="changeOff();return false">
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Javascript DOM problem when using certain Doctype - see example
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14972 seconds with 12 queries