Wednesday, April 16, 2008

Showing/Hiding controls using javascript

Showing and hiding controls is a common requirement for a web application. This is how you do it using javascript.

Snippets:

To show:
document.getElementById('<%= textboxToUse.ClientID %>').style.display = '';
To hide:
document.getElementById('<%= textboxToUse.ClientID %>').style.display = 'none';

Where in:
textboxToUse.ClientID returns the id of the control.

Works on IE and Firefox.

Attached is the sample code which includes static and dynamic version.
Dynamic version was created in ASP.Net 2.0.
To check the dynamic just run the Sample.sln file while default.htm for static.

Download Sample (11.83 kb)

2 comments:

Leo Camalig said...

More Examples bro.... Javascript man...

Leo Camalig said...

Wala bago comments?