Skip to content

Instantly share code, notes, and snippets.

@rionmonster
Created April 18, 2016 16:25
Show Gist options
  • Save rionmonster/d5dfdcf09396afe4ef01551405bf513f to your computer and use it in GitHub Desktop.
Save rionmonster/d5dfdcf09396afe4ef01551405bf513f to your computer and use it in GitHub Desktop.
/* Inline approach */
function showDiv(elem){
// If your value is not "Select", then show the next option
document.getElementById('stepsHIDDEN').style.display = (elem.value != 'Select') ? "block" : "none";
// If your value is "foo", then show another element
document.getElementById('showMeOn42').style.display = (elem.value == '42') ? "block" : "none";
}
/* Switch statement approach */
function showDiv(elem){
switch(elem.value){
case 'Select':
// Handle logic if 'Select' is selected
document.getElementById('stepsHIDDEN').style.display = 'none';
break;
case '1':
// Handle logic if '1' is selected
break;
default:
// If your value is neither 'Select' or '1', do something
document.getElementById('stepsHIDDEN').style.display = 'block';
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment