Last active
December 21, 2015 01:59
-
-
Save HituziANDO/6232063 to your computer and use it in GitHub Desktop.
HTMLでプルダウンリストの選択した値の取得方法をよく忘れてしまうのでメモ。
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
<select id="selXxx" onchange="onChange(this)"> | |
<option value="hoge" selected>hoge</option> | |
<option value="foo">foo</option> | |
<option value="bar">bar</option> | |
</select> | |
<script> | |
function onChange (selector) { | |
var val = selector.options[selector.selectedIndex].value; | |
if (val == "hoge") { | |
// something | |
} | |
else if (val == "foo") { | |
// something | |
} | |
else if (val == "bar") { | |
// something | |
} | |
else { | |
// something | |
} | |
} | |
</script> | |
<!-- Use jQuery --> | |
<script> | |
var val = $('#selXxx option:selected').val(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment