Created
December 28, 2012 04:49
-
-
Save ThomasGaubert/4394605 to your computer and use it in GitHub Desktop.
Dropdown selection changer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $options = $("#options"); | |
var options = [ | |
{id: "0", value: "Select one..."}, | |
{id: "1", value: "Choice 1"}, | |
{id: "2", value: "Choice 2"}, | |
{id: "3", value: "Choice 3"}, | |
{id: "4", value: "Choice 4"} | |
]; | |
function getOptions() { | |
var optionId = $options.val(); | |
if(optionId == 0) { | |
document.getElementById("result").innerHTML=''; | |
} | |
if(optionId == 1) { | |
document.getElementById("result").innerHTML='You chose option 1'; | |
} | |
if(optionId == 2) { | |
document.getElementById("result").innerHTML='You chose option 2'; | |
} | |
if(optionId == 3) { | |
document.getElementById("result").innerHTML='You chose option 3'; | |
} | |
if(optionId == 4) { | |
document.getElementById("result").innerHTML='You chose option 4'; | |
} | |
} | |
for (i = 0; i < options.length; i++) { | |
$options.append("<option value='" + options[i].id + "'>" + options[i].value + "</option>"); | |
} | |
getOptions(); | |
$options.on("change", function(){ | |
getOptions(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<select id="options"></select> | |
<br> | |
<div id="result"></div> | |
</body> | |
<script src="jquery.js"></script> | |
<script src="changer.js"></script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment