개발일지/JavaScript + jquery
[js] select에서 단일 입력 및 출력(전공선택)
연습용365
2021. 9. 8. 14:48
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>전공 체크</title>
<script>
function Check(ff){
var idx = ff.ss.options[ff.ss.selectedIndex].value;
document.write(idx);
}
</script>
</head>
<body>
<form>
<fieldset>
<legend>전공</legend>
<select name="ss">
<option value="컴퓨터">컴퓨터</option>
<option value="정보통신">정보통신</option>
<option value="법학">법학</option>
<option value="경영학">경영학</option>
<option value="영문학">영문학</option>
</select>
<input type="button" value="전공선택" onclick="Check(this.form);">
</fieldset>
</form>
</body>
</html>
var idx = ff.ss.options[ff.ss.selectedIndex].value;
ff.ss.셀렉트 되어 있는 것을 찾는다.
value 그걸 갖고와라
ff 폼
이름이 ss인 것에
selectedIndex 선택되어진 것
value 갖고와라
멀티가 아니라 하나만 갖고 와라
여기서 selectedIndex 이 문장은 select문에서 사용함
document.write(idx);
--> 페이지에 갖고 와라