Skip to content

Instantly share code, notes, and snippets.

@HituziANDO
Last active December 21, 2015 01:59
Show Gist options
  • Save HituziANDO/6232063 to your computer and use it in GitHub Desktop.
Save HituziANDO/6232063 to your computer and use it in GitHub Desktop.
HTMLでプルダウンリストの選択した値の取得方法をよく忘れてしまうのでメモ。
<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