HTML Select 박스에서 option value이나 text를 가져올 때 다음과 같은 방법을 쓴다.


Select박스에서 이벤트 발생 시 자바스크립트 호출

<select id="num" onchange="selectNum()">

<option value = "1" selected>하나</option>

<option value = "2">둘</option>

</select>



Select박스에서 선택한 값의 option value,text 가져오기

function selectNum(){

var numSelect = document.getElementById("num");


// text 가져오기

var text = numSelect.options[document.getElementById("num").selectedIndex].text;


// option value 가져오기

var value = numSelect.options[document.getElementById("num").selectedIndex].value;

+ Recent posts