<%@ page language="java" contentType="text/html; charset=EUC-KR"

pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<select id='fruits' name='fruits' size='6' onchange='fruits_selected()' multiple="multiple"

style="width: 200px;">

<option value='banana'>바나나</option>

<option value='lemon'>레몬</option>

<option value='apple'>사과</option>

<option value='banana'>바나나</option>

<option value='lemon'>레몬</option>

<option value='apple'>사과</option>

<option value='banana'>바나나</option>

</select>


<script>

function fruits_selected() {

var obj = document.getElementById('fruits');

var index = obj.selectedIndex;

var value = obj.options[index].value;

var text = obj.options[index].text;

for(var i=0; i< obj.length; i++){

if(obj.options[i].selected == true){

alert(obj.options[i].text)

}

}

console.log('------------------');

console.log('index = [' + index + ']');

console.log('value = [' + value + ']');

console.log('text = [' + text + ']');

}

</script>


</body>

</html>

블로그 이미지

왕왕왕왕

,