How can I make some input fields visible and invisible at runtime using JavaScript?

Jayesh Nazre

You can use the visibility property. The following code will work in Internet Explorer:


<html>
<head>
<script language=javascript>
function hide() {
var div_ref = document.all("id_div");
  div_ref.style.visibility = "hidden";
}

function show() {
var div_ref = document.all("id_div");
  div_ref.style.visibility = "visible";
}
</script>
</head>
<body>
<form name=frm_test id=frm_test>
<input type=button Value=Hide onclick=hide()>
<input type=button Value=Show onclick=show()>
<div id=id_div>
<input type=text value="HELLO WORLD">
</div>
</form>
</body>
</html>
And the following code will work in Netscape browsers:

<html>
<head>
<script language=javascript>
function hide() {
var div_ref = document.layers["id_div"];
  div_ref.visibility = "hide";
}

function show() {
var div_ref = document.layers["id_div"];
  div_ref.visibility = "show";
}
</script>
</head>
<body>

<form name=frm_test id=frm_test>

<input type=button Value=Hide onclick=hide()>
<input type=button Value=Show onclick=show()>

<layer name=id_div id=id_div visibility=show>
<form>
<input type=text value="HELLO WORLD">
</form>
</layer>

</form>

</body>
</html>
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact