PDA

View Full Version : document.all and Firefox problems



cracken
04-18-2008, 10:38 PM
Hi

I have the following JavaScript which does not work in Firefox, could anyone advise me how to get this to work. Works fine in IE.

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type=text/javascript>
function toggleT(_w,_h) {
if (document.all) { // is IE
if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
} else { // is NS?
if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
}
}
</script>
</head>
<body>

<form>
Property Type ? (moving from)*<br />
<input name="propertyType" type="radio" value="House" onClick="toggleT('divt1','h')" />House&nbsp;
<input name="propertyType" type="radio" value="Flat" onClick="toggleT('divt1','s')"/>Flat&nbsp;
<span id="divt1" style="visibility:hidden;position:relative;top:0;left:0">
<input type="text" size="1" on />&nbsp;Floor</span>
</form>
</body>
</html>

Any input would be much app.
Thanks in advance.

Mark :)

Master_script_maker
04-19-2008, 12:09 AM
function toggleT(_w,_h) {
if (document.all) { // is IE
if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
} else { // is NS?
if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
}
}
you dont need eval:

function toggleT(_w,_h) {
if (document.all) { // is IE
if (_h=='s') document.all._w.style.visibility='visible';
if (_h=='h') document.all._w.style.visibility='hidden';
} else { // is NS?
if (_h=='s') document.layers[_w].visibility='show';
if (_h=='h') document.layers[_w].visibility='hide';
}
}

cracken
04-21-2008, 12:17 PM
Hi
Thanks for your input but that did not work for Firefox, I have read that document.all is not supported in any other browsers than IE and it should be replaced with getelementbyID, is this script slavagable or should I bin it ?

boogyman
04-21-2008, 12:28 PM
you dont need eval:

function toggleT(_w,_h) {
if (document.all) { // is IE
if (_h=='s') document.all._w.style.visibility='visible';
if (_h=='h') eval("document.all._w.style.visibility='hidden';
} else { // is NS?
if (_h=='s') document.layers[_w].visibility='show';
if (_h=='h') document.layers[_w].visibility='hide';
}
}

you either forgot to remove that eval or you forgot to complete it.


eval("document.all._w.style.visibility='hidden'");

Master_script_maker
04-21-2008, 07:48 PM
thanks i meant to remove it.
cracken, does the _w variable contain a name?