-
셀렉트 박스 선택한 것이 다음 셀렉트 박스로 이동하게끔 하기프로그램/JavaScript 2008. 8. 28. 14:00
<html>
<head><SCRIPT LANGUAGE="JavaScript">
function moveOver() {
var boxLength = document.choiceForm.choiceBox.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText = document.choiceForm.available.options[selectedItem].text;
var selectedValue = document.choiceForm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.choiceBox.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.choiceBox.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}function removeMe() {
var boxLength = document.choiceForm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.choiceForm.choiceBox.options[i].selected) {
arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
document.choiceForm.choiceBox.options[i] = null;
}
}
boxLength = document.choiceForm.choiceBox.length;
}
}</script>
</HEAD>
<BODY><center>
<form name="choiceForm">
<table border=0>
<tr>
<td valign="top" width=175><br>
<select name="available" style="width:150" size=10 onchange="moveOver();">
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
</select>
</td>
<td valign="top"><br>
<select multiple name="choiceBox" style="width:150;" size="10">
</select>
</td>
</tr>
<tr>
<td colspan=2 height=10>
<input type="button" value="제거" onclick="removeMe();">
</td>
</tr>
</table>
</form>
</center>'프로그램 > JavaScript' 카테고리의 다른 글
주소 복사하기 (0) 2008.12.19 getElementById 와 getElementsByName 의 차이 (2) 2008.11.26 셀렉트박스 연계 (0) 2008.08.28 자바스크립트 문자열 자르기(문자메세지등...) (0) 2008.08.22 여태 잘못 알고 있었던 자바스크립트 기초... (0) 2008.01.23 자바스크립트 디버거 (0) 2008.01.03 Javascript 새창 띄우기를 다음과 같이도 한다. (0) 2007.12.03