|
Such as the title: This is the code I wrote. The master shows me how to assign all the values of the js script to the select control. I got it in the background, thanks.
<tr>
<td align = "right" valign = "top"> <font color = # FF6600> * </ font> <b> </ b> Working place </ td>
<td> <select name = "selloc1" size = "5" multiple id = "selloc1" runat = server style = "width: 160">
<option value = '# 5 #'> Beijing / Beijing </ option
</ select>
</ td>
<td> <INPUT TYPE = "BUTTON" NAME = "Input3" VALUE = "Add >>" OnClick = "JavaScript: additem (selloc1, selloc2)">
<BR> <INPUT TYPE = "BUTTON" NAME = "Input22" VALUE = "<< Remove" OnClick = "JavaScript: delitem (selloc2)"> </ td>
<td> <select name = "selloc2" size = "5" MULTIPLE id = "selloc2" style = "width: 160">
</ select>
</ td>
</ tr>
-------------------------- javascrip has been implemented without problems ------------------- ----
<script language = javascript>
<!-begin
function additem (sel1, sel2) {
var flag;
var count = 0;
for (var x = 0; x <sel1.length; x ++) {
var opt = sel1.options [x];
if (opt.selected) {
count = count + 1;
if (count> 5) {
alert ("No more than 5 selected items!");
return;
}
}
}
if (count> 1&&sel1.options [0] .value == 0&&sel1.options [0] .selected) {
alert ("You have selected [Unlimited] items, no other items can be selected!");
return;
}
for (var x = 0; x <sel1.length; x ++) {
var opt = sel1.options [x];
if (opt.selected) {
flag = true;
for (var y = 0; y <sel2.length; y ++) {
var myopt = sel2.options [y];
if (myopt.value == opt.value) {
flag = false;
}
else if (sel2.options [0] .value == 0) {
alert ("You have selected [Unlimited] items, no other items can be selected!");
return;
}
}
if (flag) {
if (sel1.options [0] .selected&&sel1.options [0] .value == 0) {
for (var x = sel2.length-1; x> = 0; x-) {
sel2.options [x] = null;
}
sel2.options [0] = new Option (opt.text, opt.value, 0, 0);
} else if (sel2.length> 4) {
alert ("No more than 5 selected items!");
return;
}
else {
sel2.options [sel2.options.length] = new Option (opt.text, opt.value, 0, 0);
}
}
}
} |
|