Transferring value from one select box to another

R

Raghuram Banda

Hi All,

Can any one please look into the following code and tell me where I went
wrong

<html>
<head>
<script language="JavaScript">
function transferItem(srcId, destId) {
var destObj = document.getElementById(destId);
var srcObj = document.getElementById(srcId);
for(var i=0; i<srcObj.length; i++)
if(srcObj.options.selected) {
var srcTxt = srcObj.options.text;
var srcVal = srcObj.options.value;
var newOpt = document.createElement("OPTION");
newOpt.text = srcTxt;
newOpt.value = srcVal;
destObj.add(newOpt, null);
}
for(var i=0; i<srcObj.length; i++) {
if(srcObj.options.selected) {
srcObj.remove(i);
}
}
}
</script>
<body>
<table width="100%" height="335">
<tr>
<td width="33%" height="329">
<select name="sourceSelect" id="sourceSelect" size="4" Multiple>
<option value ="volvo">Volvo</option>
<option value ="saab">Saab</option>
<option value ="opel">Opel</option>
<option value ="audi">Audi</option>
</select>
</td>
<td width="33%" height="329">
<button onClick='transferItem("sourceSelect","destSelect")'> Add
</button>
<br>
<br>
<button onClick='transferItem("destSelect","sourceSelect")'> Remove
</button>
</td>
<td width="33%" height="329">
<select name="destSelect" id="destSelect" size="3" Multiple>
</select>
</td>
</tr>
</table>
</body>
</html>

Actually I have written the script to transfer the selected options
single/multiple(contiguous/non-contiguous) from source select box
to destination select box and vice versa.

This code is working fine in NN6+, the problem is when I'm selecting
contiguous options from source/destination select
box and click on add/remove button I'm gettting problem not all selected
options are deleted from source select box.

Sorry for lengthy mail.

Thanks in advance
 
G

G Roydor

essayez de parcourir la liste des options dans le sens Imax => Imin

for(var i=srcObj.length; i=0; i--)

vérifier les limites dans ma proposition
Bonne chance
GR

Raghuram Banda a écrit:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top