I am working on a search box that displays different options based on a users selection via dropdown box. Basically I need a really clean, light-weight method for switching out different divs without reloading the page. Im new to JS, but I know enough that there should be some really simple way of setting the display property using JS – Im just not totally sure how to go about it. Any help would be really appreciated, thanks.
Share
Not using jQuery, here’s a little something that can do it. Real basic DOM stuff, but anyway…
It is commented to death, but in general you give it a container id (in which your elements to show/hide are), and then some hide-all-then-show-one-of-them is done in the
selectelement’sonchange. The way to retrieve element to show is basename+suffix (and the suffix is the value of the select’s option for a corresponding element).Here: