View Full Version : How to Hide Textfield in IE and Netscape

06-04-2003, 12:18 PM
Hi All,

I use this code to hide a textfield, it works in IE but it doesn't work when I load the page in Netscape. Any Help?


//To Hide Textbox

document.getElementById("sr").style.display = 'none'



06-04-2003, 12:54 PM
It works in NS 6 or higher... If you try it in an older version of NS, you must use first a browser detector and then, probably, for NS 4.x you may try the syntax


instead of

document GetElementById(id).style

Roy Sinclair
06-04-2003, 04:20 PM
It isn't going to work in Netscape 4.x at all. In NS4 you can only show/hide entire layers, putting the input field into a layer would require adding another set of <form></form> for the field and then more code to pull the result from that field to inset it into a hidden field in the main form. That's a lot of work just to support an obsolete, bug infested browser used by a very small percentage of the web. The best approach for handling NS4 is to treat it just like a version 3 browser and turn off all the "dynamic" sttuff.

06-04-2003, 04:39 PM
It is not so hard to hide/show an element using "id", even in NS 4.x. It is just another syntax. True, you have to use <layer> and <ilayer> tags, as NS 4.x cannot recognize <div> or <span> to be sure that the "id" atribute is accepted, but, after you run a browser detector script, and an objectSetup function, the rest is simple, something like:

function layerSetup(id,visibility) {
if (is.ie5||is.ie55||is.ie6||is.ns6){
this.obj = document.getElementById(id).style;
this.obj.visibility = visibility;
return this.obj;
} else if(is.ie4) {
this.obj = document.all[id].style;
this.obj.visibility = visibility;
return this.obj;
} else if(is.ns4) {
this.obj = document.layers[id];
this.obj.visibility = visibility;
return this.obj;

...now you can make an element visible/hidden for IE4 and NS4 also... If you want to, you may include other style, arguments, such as position, and make thus the object move...

Need anyone the full script?