2つのオプションを選択しようとすると、最初のオプションが2回表示されます。ここでJavascriptで複数選択を追加したい
はコードです:
<head>
<script type="text/javascript">
function choices() {
var y = document.getElementById("s");
var x = document.getElementById("output");
var choice = y.value;
for (i = 1; i <= 3; i++) {
var current = y[i];
if (current.selected == true) {
x.innerHTML += "the language is, " + choice + "<br>";
}
}
}
</script>
</head>
<body>
<form action="">
<fieldset>
<select id="s" multiple="multiple" size="4">
<option>--Choose language--</option>
<option value="HTML">HTML</option>
<option value="JAVA">JAVA</option>
<option value="PHP">PHP</option>
</select>
<input type="button" value="show" onclick="choices()">
</fieldset>
</form>
<div id="output"></div>
</body>
refere https://stackoverflow.com/questions/2049710/how-to-select-options-in-multiple-select-list-with-jquery –