Restoration
1/30/2017 - 8:00 AM

セレクトボックスの値を取得

セレクトボックスの値を取得

<select name="select" id="select">
	<option value="1">Value1</option>
	<option value="2">Value2</option>
	<option value="3">Value3</option>
</select>
// JavaScriptを使って取得する
var selects = document.getElementById('select');
var option = document.getElementById('select').options;
var value = option[selects.selectedIndex].text;
//value値で取得するなら
//var value = option[selects.selectedIndex].value;
document.write(value);

// jQueryを使って取得する
jQuery(function($){
	$('#select option:selected').text();
	$('#select').children(':selected').text();
});