다중셀렉트간 항목다중이동 및 순서설정 > script

본문 바로가기
사이트 내 전체검색

script

다중셀렉트간 항목다중이동 및 순서설정

페이지 정보

작성자 서방님 댓글 0건 조회 117회 작성일 07-02-21 09:34

본문

select.gif


다중셀렉트박스간의 항목이동과 이동된 항목들의 순서를 변경 해주는 소스 입니다.
필요하니 별걸 다 만들게 되네요;;;

<script language=javascript>
function gor(argSel,argRes)
{
formSel=eval("document.reg."+argSel);

j=formSel.length;

for(var i=0;i<document.reg.a.length;i++)
{
                if(document.reg.a.options[i].selected && document.reg.a.options[i].value)
                {
                document.reg.a.options[i].selected=false;

                chk_same=0;

                        for(var k=0;k<formSel.length;k++)
                        {
                                if(document.reg.a.options[i].value==formSel.options[k].value)
                                {
                                chk_same=1;                               
                                }       
                        }                       

                        if(!chk_same)
                        {
                        formSel.options[j]=new Option(document.reg.a.options[i].text,document.reg.a.options[i].value);

                        j++;
                        }
                }
}

get_result(argSel,argRes)
}

function gol(argSel,argRes)
{
formSel=eval("document.reg."+argSel);

buff=new Array();
j=0;

for(var i=formSel.length-1;i>=0;i--)
{
                if(formSel.options[i].selected && formSel.options[i].value)
                {
                formSel.options[i] = null;
                }
}

get_result(argSel,argRes);
}

function get_result(argSel,argRes)
{
formSel=eval("document.reg."+argSel);
formRes=eval("document.reg."+argRes);

res=new Array();

for(var i=0;i<formSel.length;i++)
{
res[i]=formSel.options[i].value;
}

res=res.join("@");
formRes.value=res;
}

function gou(argSel,argRes)
{
formSel                = eval("document.reg."+argSel);

        if(!formSel.value)
        {
        return;
        }

thisIndex        = formSel.selectedIndex;

        if(!thisIndex)
        {
        return;
        }

formSel.value=null;

prevIndex=thisIndex-1;

tempText=formSel.options[prevIndex].text;
tempValue=formSel.options[prevIndex].value;

formSel.options[prevIndex]        = new Option(formSel.options[thisIndex].text,formSel.options[thisIndex].value);

formSel.options[thisIndex]        = new Option(tempText,tempValue);

formSel.value=formSel.options[prevIndex].value;

get_result(argSel,argRes);
}

function god(argSel,argRes)
{
formSel                = eval("document.reg."+argSel);

        if(!formSel.value)
        {
        return;
        }

thisIndex        = formSel.selectedIndex;

        if(thisIndex+1>=formSel.length)
        {
        return;
        }

formSel.value=null;

prevIndex=thisIndex+1;

tempText=formSel.options[prevIndex].text;
tempValue=formSel.options[prevIndex].value;

formSel.options[prevIndex]        = new Option(formSel.options[thisIndex].text,formSel.options[thisIndex].value);

formSel.options[thisIndex]        = new Option(tempText,tempValue);

formSel.value=formSel.options[prevIndex].value;

get_result(argSel,argRes);
}
</script>

 

<table border=0 cellpadding=0 cellspacing=0>
<form name=reg>
<tr>
<td rowspan=6>
<select name=a size=20 style=width:200 multiple>
<option value='1'>짜장면</option>
<option value='2'>짬뽕</option>
<option value='3'>볶음밥</option>
<option value='4'>라면</option>
<option value='5'>김치</option>
<option value='6'>단무지</option>
<option value='7'>공기밥</option>
<option value='8'>김밥</option>
<option value='9'>라면</option>
<option value='10'>백반</option>
</select>
</td>
<td></td><td>아침메뉴</td><td></td>
</tr>
<tr>
<td>
&nbsp;<input class=button type=button value=' > ' onclick=gor('b1','res1')>&nbsp;
<br>
&nbsp;<input class=button type=button value=' < ' onclick=gol('b1','res1')>&nbsp;
</td>
<td>
<select name=b1 size=5 style=width:200>
</select>
</td>
<td>
&nbsp;<input class=button type=button value=' ↑ ' onclick=gou('b1','res1')>&nbsp;
<br>
&nbsp;<input class=button type=button value=' ↓ ' onclick=god('b1','res1')>&nbsp;
</td>
</tr>
<tr>
<td></td><td>점심메뉴</td></td><td></td>
</tr>
<tr>
<td>
&nbsp;<input class=button type=button value=' > ' onclick=gor('b2','res2')>&nbsp;
<br>
&nbsp;<input class=button type=button value=' < ' onclick=gol('b2','res2')>&nbsp;
</td>
<td>
<select name=b2 size=5 style=width:200>
</select>
</td>
<td>
&nbsp;<input class=button type=button value=' ↑ ' onclick=gou('b2','res2')>&nbsp;
<br>
&nbsp;<input class=button type=button value=' ↓ ' onclick=god('b2','res2')>&nbsp;
</td>
</tr>

<tr>
<td></td><td>저녁메뉴</td></td><td></td>
</tr>
<tr>
<td>
&nbsp;<input class=button type=button value=' > ' onclick=gor('b3','res3')>&nbsp;
<br>
&nbsp;<input class=button type=button value=' < ' onclick=gol('b3','res3')>&nbsp;
</td>
<td>
<select name=b3 size=5 style=width:200>
</select>
</td>
<td>
&nbsp;<input class=button type=button value=' ↑ ' onclick=gou('b3','res3')>&nbsp;
<br>
&nbsp;<input class=button type=button value=' ↓ ' onclick=god('b3','res3')>&nbsp;
</td>
</tr>
</table>

<br>
결과값<br>
<input type=text name=res1 size=30><br>
<input type=text name=res2 size=30><br>
<input type=text name=res3 size=30><br>
</form>


출처 : http://libphp.com/main/data/preview.php?no=3109

댓글목록

등록된 댓글이 없습니다.

Total 846건 45 페이지
게시물 검색

회원로그인

접속자집계

오늘
25
어제
302
최대
1,347
전체
155,086
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.