/    Sign up×
Community /Pin to ProfileBookmark

Moving data across multiple select box problem.

Please see the code below:
Every thing works fine except
When i want to remove the values from delete Users. When i remove them one by one they get added in their right select Box. ALso when i select only Active Users or Inactive Users they get added in the right select Box. Problem is when i select All every thing gets added in the In Active User list. dotn know what i am doing wrong here is the code:
Code:
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE=”JavaScript”>

var NS4 = (navigator.appName == “Netscape” && parseInt(navigator.appVersion) < 5);
function addOption(theSel, theText, theValue)
{
var newOpt = new Option(theText, theValue);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{
var selLength = theSel.length;
if(selLength>0)
{
theSel.options[theIndex] = null;
}
}

function moveOptions(theActiveUserFrom,theInactiveUserFrom, theDeleteTo)
{

var selLength = theActiveUserFrom.length;
var inactiveUserLength = theInactiveUserFrom.length;
var deleteSelectBox = theDeleteTo.length;

var selectedText = new Array();
var selectedValues = new Array();
var selectedCount = 0;
var i;

// Find the selected Options in reverse order
// and delete them from the ‘from’ Select.
for(i=selLength-1; i>=0; i–)
{
if(theActiveUserFrom.options[i].selected)
{
selectedText[selectedCount] = theActiveUserFrom.options[i].text;
selectedValues[selectedCount] = theActiveUserFrom.options[i].value;
deleteOption(theActiveUserFrom, i);
selectedCount++;
}

}

for(i=inactiveUserLength-1; i>=0; i–)
{
if(theInactiveUserFrom.options[i].selected)
{
selectedText[selectedCount] = theInactiveUserFrom.options[i].text;
selectedValues[selectedCount] = theInactiveUserFrom.options[i].value;
deleteOption(theInactiveUserFrom, i);
selectedCount++;
}
}

// Add the selected text/values in reverse order.
// This will add the Options to the ‘to’ Select
// in the same order as they were in the ‘from’ Select.
for(i=selectedCount-1; i>=0; i–)
{

addOption(theDeleteTo, selectedText[i], selectedValues[i]);
}

if(NS4) history.go(0);
}

function moveBack(theDeleteFrom, theActiveUserTo,theInactiveUserTo)
{

var deleteSelectBox = document.getElementById(‘DeleteUsers’);

var selectedText = new Array();
var selectedValues = new Array();
var selectedCount = 0;
var i;

// Find the selected Options in reverse order
// and delete them from the ‘from’ Select.
for(i=deleteSelectBox.length-1; i>=0; i–)
{
// Check for the value
if(deleteSelectBox.options[i].selected)
{
if(deleteSelectBox.options[i].value == “active”)
{
alert(“Active”);
var optThis = new Option();
optThis.text = deleteSelectBox[deleteSelectBox.selectedIndex].text;
optThis.value = deleteSelectBox[deleteSelectBox.selectedIndex].value;
optThis.defaultSelected = false;
optThis.Selected = false;
//remove from left
deleteSelectBox.remove(deleteSelectBox.selectedIndex);
//add to right
document.getElementById(‘ActiveUserList’).add(optThis);

} else
{
alert(“Inactive”);
var optThis = new Option();
optThis.text = deleteSelectBox[deleteSelectBox.selectedIndex].text;
optThis.value = deleteSelectBox[deleteSelectBox.selectedIndex].value;
optThis.defaultSelected = false;
optThis.Selected = false;
//remove from left bottom
deleteSelectBox.remove(deleteSelectBox.selectedIndex);
//add to right
document.getElementById(‘InActiveUsers’).add(optThis);

}
}
}
}

</SCRIPT>

</HEAD>
<body>

<FORM name=myForm METHOD=POST ACTION=”UserEditSrv”>

<TABLE BGCOLOR=”#FFFFFF” BORDER=0 CELLPADDING=2 CELLSPACING=0 ALIGN=CENTER>

<TR>
<TD COLSPAN=3>
<FONT SIZE=2 FACE=”Arial, Helvetica, sans serif” COLOR=”#000000″>
<B></B>
</TD>
</TR>

<TR>
<TD align=LEFT>
<table width=”100″ border=”0″ align=”center”>
<tr>
<TD> </TD>
<td>
</td>
</tr>
<tr>
<TD> </TD>
<td><FONT SIZE=2 FACE=”Arial, Helvetica, sans serif” COLOR=”#000000″>
<B>Active Users</B>
</td>
</tr>
<tr>
<TD> </TD>
<TD ALIGN=left VALIGN=center>
<SELECT NAME=”ActiveUserList” MULTIPLE SIZE=15 width=220 id =”ActiveUserList” >
<!– Display All current Users –>
<OPTION value=”active”>Active1 </OPTION>
<OPTION value=”active”>Active2 </OPTION>
<OPTION value=”active”>Active3 </OPTION>
<OPTION value=”active”>Active4 </OPTION>
<OPTION value=”active”>Active5 </OPTION>
<OPTION value=”active”>Active6 </OPTION>
<OPTION value=”active”>Active7 </OPTION>
<OPTION value=”active”>Active8 </OPTION>
<OPTION value=”active”>Active9 </OPTION>
<OPTION value=”active”> Active10 </OPTION>
<OPTION value=”active”>Active11 </OPTION>
<OPTION value=”active”>Active12</OPTION>
<OPTION value=”active”>Active13</OPTION>
<OPTION value=”active”>Active14 </OPTION>
<OPTION value=”active”>Active15</OPTION>
<OPTION value=”active”>Active16</OPTION>
<OPTION value=”active”>Active17</OPTION>

</SELECT>
</TD>
</tr>
<tr>
<td><FONT SIZE=2 FACE=”Arial, Helvetica, sans serif” COLOR=”#000000″>
<B>In Active ( yy/mm/dd )</B>
</td>
<td><FONT SIZE=2 FACE=”Arial, Helvetica, sans serif” COLOR=”#000000″>
<B>In Active Users</B>
</td>

<TD ALIGN=CENTER VALIGN=center>

<TABLE WIDTH=100>
<TR>
<TD>
<INPUT TYPE=BUTTON width=100 VALUE=”Add &gt;&gt;” WIDTH=100 onclick=”moveOptions(this.form.ActiveUserList,this.form.InActiveUsers, this.form.DeleteUsers);”>
</TD>
</TR>
<TR>
<TD>
<INPUT TYPE=BUTTON width=100 VALUE=”&lt;&lt Remove” WIDTH=100 onclick=”moveBack(this.form.DeleteUsers, this.form.InActiveUsers, this.form.ActiveUserList);”>
</TD>
</TR>
</TABLE>
</TD>
</tr>
<tr>

<TD ALIGN=left VALIGN=center>
<SELECT NAME=”InactiveSince” MULTIPLE SIZE=15 width=220 disabled=”disabled”>
<!– Display the inactive period –>
<OPTION value=””>01/01/02
<OPTION value=””>01/01/02
<OPTION value=””>01/01/02
<OPTION value=””>01/01/02
<OPTION value=””>01/01/02

</SELECT>
</TD>

<TD ALIGN=left VALIGN=center>
<SELECT NAME=”InActiveUsers” MULTIPLE SIZE=15 width=220>
<!– Display the Inactive Users –>
<OPTION value=”inactive”>Inactive1
<OPTION value=”inactive”>Inactive2
<OPTION value=”inactive”>Inactive3
<OPTION value=”inactive”>Inactive4
<OPTION value=”inactive”>Inactive5

</SELECT>
</TD>

</tr>

</table>
</TD>
<!– add another TD for –>

<TD ALIGN=CENTER VALIGN=top>

<TABLE WIDTH=100>
<TR>
</br>
</br>
</br>
</br>
<td VALIGN=”top”><FONT SIZE=2 FACE=”Arial, Helvetica, sans serif” COLOR=”#000000″>
<B>Delete Users</B>
</td>
</TR>
<TR>

<TD ALIGN=left VALIGN=top>
<SELECT NAME=”DeleteUsers” MULTIPLE SIZE=25 width=220>

</SELECT>
</TD>
</TR>
</TABLE>

</TD>

</TR>
<TR>
<TD></TD>
<TD VALIGN=center ALIGN=center>
<INPUT TYPE=BUTTON VALUE=”Save Delete” WIDTH=100 onClick=”submitForm()”>
</TD>

<TD width=”150″>

</TD>

</TR>

</TABLE>
</FORM>
</BODY>

</HTML>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinFeb 02.2006 — if this is to completely remove an option, it is coded wrong:
[CODE]
function deleteOption(theSel, theIndex)
{
var selLength = theSel.length;
if(selLength>0)
{
theSel.options[theIndex] = null;
}
}
[/CODE]


this:

theSel.options[theIndex] = null;

should be:

theSel.remove(theSel[theIndex]);


If you don't have a debugger, get one. I use the microsoft script editor and that is fine for stuff like this. You can keep a check on your variables, because I think there may lay you problem
Copy linkTweet thisAlerts:
@alidar777authorFeb 02.2006 — Thanks

It is working fine. The only problem is that when i select all in delete user select box and clik on remove it all the selected data goin in to Inactive User select box.
×

Success!

Help @alidar777 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...