웹
select tag onchange
메밀국수가생각나
2021. 12. 1. 16:47
html
<select id="ISVALID" onchange="onChangeISVALID()">
<option value="VALID">유효함</option>
<option value="NOTVALID">유효하지않음</option>
</select>
JavaScript
function onChangeISVALID() {
var select_ISVALID = document.getElementById("ISVALID");
var selectValue = select_ISVALID.options[select_ISVALID.selectedIndex].value;
console.log('selectValue: ' + selectValue);
}
경험한 오류
1. 처음에selectedIndex를 selectindex라고 처서 오류가 발생했었다.
2. select tag에서 onchange 부분에 onclick 이벤트를 등록할 때 () 를 빼먹어서 오류가 발생했었다.