In the following code I set up a change handler on a select box to show and hide some follow up questions based on the value of the selection.
Further, for some valu
My advice is don't do it that way. There are a lot easier ways of doing this. Consider:
...
...
...
$(function() {
$("#select").change(function() {
var val = $(this).val();
$("div." + val").show();
$("div:not(." + val + ")").hide();
});
});
Much easier. Basically give classes to indicate what to show and hide and then there is no tracking required. An alternative is:
$(function() {
$("#select").change(function() {
var val = $(this).val();
$("div").each(function() {
if ($(this).hasClass(val)) {
$(this).show();
} else {
$(this).hide();
}
});
});
});