Click to See Complete Forum and Search --> : xhtml vs html javascript


craftymind
09-26-2003, 10:21 PM
Can anyone please tell me why this works in all browsers


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Resize Div</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function setHeight(divid, newH){
document.getElementById(divid).style.height = newH;
}
</script>
</head>

<body>
<div align="center">
<div id="resize" style="width:400px; height:200px; background-color:#FF0000;"></div>
<input type="button" onclick="setHeight('resize', 400)" value="Enlarge" />
</div>
</body>
</html>


but changing the doctype/encoding to xhtml doesn't work in non-IE browsers


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Resize Div</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function setHeight(divid, newH){
document.getElementById(divid).style.height = newH;
}
</script>
</head>

<body>
<div align="center">
<div id="resize" style="width:400px; height:200px; background-color:#FF0000;"></div>
<input type="button" onclick="setHeight('resize', 400)" value="Enlarge" />
</div>
</body>
</html>

Khalid Ali
09-26-2003, 10:58 PM
run your code through this validator

http://validator.w3.org/

and you will know why

craftymind
09-26-2003, 11:08 PM
This is what I get
"This Page Tentatively Validates As XHTML 1.0 Transitional (Tentatively Valid)!"


And if I remove
<?xml version="1.0" encoding="UTF-8"?>
from the top of the document, then I get
"This Page Is Valid XHTML 1.0 Transitional!"

but the script still doesn't work in non-IE browsers

Khalid Ali
09-26-2003, 11:20 PM
oh ok..I missed that part...

just add px with the height value like

newH+"px";

craftymind
09-26-2003, 11:32 PM
woohoo

Thanks Khalid, that did it :)

Khalid Ali
09-27-2003, 09:01 AM
:)
my pleasure