Monday, May 11, 2009

Checking the type of an element using javascript

*Watch out, this is oldskool javascript ;)*

Here is the situation..

We have multiple dropdownlists, and with each dropdownlist belongs another type of element (ex. a textbox, a dropdownlist, ...). For each element, we need another piece of code. So I wrote one small function which can be used for all these dropdownlists.

Here is the function.



A little explanation..

This function has 3 parameters: The dropdownlist to check the selected value of, the control to toggle, and the value to check.

When the value of dropdownlist to check equals the value to check, I show the control to toggle. Else I check what type the element to toggle is, so I can execute the corresponding code.

I hope this saves someone a few minutes :)

No comments:

Post a Comment