Esse é um exemplo de como manipular dados entre selects (listbox).
Espero que seja de grande ajuda!
<html>
<head>
<script language='javascript'><!--
function Adiciona() {
var i=1;
var n=0;
do {
var y1="document.form2.s"+i+".value";
if (eval(y1)=='')
n=i;
i++;
} while (i<=5 && n==0);
var vs1=document.form1.campo2.selectedIndex;
if (vs1!=-1){
var x1="document.form2.s"+n+".value=document.form1.campo2.options[vs1].text;"
eval(x1)
eval("document.form2.hs"+n+".value=document.form1.campo2.options[vs1].value;");
var x3="document.form2.b"+n+".disabled=false;"
eval(x3)
document.form1.campo2.options[vs1]=null;
if (n==5)
document.form1.botao1.disabled=true;
}
}
function Remove(n) {
j=0;
do {
var y="document.form1.campo2.options["+j+"]";
j++;
} while (eval(y)!=null);
j--;
var d2text=eval("document.form2.s"+n+".value");
var d2val=eval("document.form2.hs"+n+".value");
dop2="var option2 = new Option('"+d2text+"', '"+d2val+"');";
eval(dop2);
var x2="document.form1.campo2.options["+j+"]=option2;"
eval(x2);
eval("document.form2.b"+n+".disabled=true;");
eval("document.form2.s"+n+".value='';");
document.form1.botao1.disabled=false;
}
--></script>
</head><body>
<form name='form1'>
<select name='campo2' size='11'>
<option value='1'> Nome1
<option value='2'> Nome2
<option value='3'> Nome3
<option value='4'> Nome4
<option value='5'> Nome5
<option value='6'> Nome6
<option value='7'> Nome7
<option value='8'> Nome8
<option value='9'> Nome9
<option value='10'> Nome10
<option value='11'> Nome11
</select>
<input name='botao1' type='button' value='Adiciona' onclick="Adiciona();"></form>
<form name='form2' action='salvajogada.asp' method='post'>
<input type='text' name='s1' readonly size='10'>
<input type='hidden' name='hs1' value=''>
<input type='button' name='b1' disabled value='Remove' onclick='Remove(1)'><br>
<input type='text' name='s2' readonly size='10'>
<input type='hidden' name='hs2' value=''>
<input type='button' name='b2' disabled value='Remove' onclick='Remove(2)'><br>
<input type='text' name='s3' readonly size='10'>
<input type='hidden' name='hs3' value=''>
<input type='button' name='b3' disabled value='Remove' onclick='Remove(3)'><br>
<input type='text' name='s4' readonly size='10'>
<input type='hidden' name='hs4' value=''>
<input type='button' name='b4' disabled value='Remove' onclick='Remove(4)'><br>
<input type='text' name='s5' readonly size='10'>
<input type='hidden' name='hs5' value=''>
<input type='button' name='b5' disabled value='Remove' onclick='Remove(5)'><br>
</form>
</body></html>
0 comentários:
Postar um comentário