Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving select multiple contents to another select multiple

Status
Not open for further replies.

timmbo

Programmer
Feb 22, 2001
167
US
Hello Everyone,

I am new to JavaScript and to this forum so please forgive me for any inaccuracies. My apologies for the long post.

I have a two-part question.

First question:
I have a select multiple loaded with accounts. The user can select various accounts and hits a button and the account will move to my &quot;Selected Accounts&quot; select multiple. This works fine if my input type=&quot;button&quot;. I want to be able to display an image on the button. When I have <input type=image src...>, the second select multiple shows the account upon selection. But an alert window appears showing account number selected. If I click OK, alert disappears and the second select multiple clears.
Can this be done with an image src on a button? How?

Second question:
I have another button enabling the user to move all contents of first select multiple to second select multiple. When button is clicked, I get windows memory error and IE closes.
Is there a way of doing this? How?

Any and all suggestion would be most appreciated. Below are nippets of my code. If you need more, let me know.

TIA


<Form Name=&quot;RptOptions&quot; onSubmit=&quot;populateHidden(document.RptOptions.SelAccounts,document.RptOptions.hidden1)&quot;>


<select name=&quot;AvailAccounts&quot; multiple size=&quot;8&quot; style=&quot;width:130px;&quot; width=&quot;140&quot;>
<option value=&quot;2300883&quot;>2300883
<option value=&quot;3889100682&quot;>3889100682
<option value=&quot;1006970459&quot;>1006970459
<option value=&quot;1009562127&quot;>1009562127
<option value=&quot;2222222222&quot;>2222222222
<option value=&quot;6204803355&quot;>6204803355
<option value=&quot;9230063411&quot;>9230063411
<option value=&quot;1111111111&quot;>1111111111
<option value=&quot;2222222222&quot;>2222222222
<option value=&quot;3333333333&quot;>3333333333
<option value=&quot;4444444444&quot;>4444444444
</select>


<input type=&quot;button&quot; value=&quot; > &quot;image src=&quot;button_right.gif&quot; onclick=&quot;if (document.images)copySelected(document.RptOptions.AvailAccounts,document.RptOptions.SelAccounts)&quot;><br><br>
<input type=image src=&quot;button_all_right.gif&quot; onclick=&quot;if (document.images) copyAll (document.RptOptions.AvailAccounts,document.RptOptions.SelAccounts)&quot;><br><br>
<input type=&quot;button&quot; value=&quot; < &quot;image src=&quot;button_left.gif&quot; onclick=&quot;if (document.images) copySelected(document.RptOptions.SelAccounts,document.RptOptions.AvailAccounts)&quot;><br><br>
<input type=image src=&quot;button_all_left.gif&quot; onclick=&quot;if (document.images) copyAll (document.RptOptions.SelAccounts,document.RptOptions.AvailAccounts)&quot;>

<select name=&quot;SelAccounts&quot; multiple size=&quot;8&quot; style=&quot;width:130px;&quot; width=&quot;140&quot;>

<input type=&quot;hidden&quot; name=&quot;hidden1&quot;>

JavaScript:
function copySelected(fromObject,toObject) {
for (var i=0, l=fromObject.options.length;i<l;i++) {
if (fromObject.options.selected)
addOption(toObject,fromObject.options.text,fromObject.options.value);
}
for (var i=fromObject.options.length-1;i>-1;i--) {
if (fromObject.options.selected)
deleteOption(fromObject,i);
}
}

function copyAll(fromObject,toObject) {
for (var i=0, l=fromObject.options.length;i<l;i++) {
addOption(toObject,fromObject.options.text,fromObject.options.value);
}
for (var i=fromObject.options.length-1;i>-1;i--) {
deleteOption(fromObject,i);
}
}

function populateHidden(fromObject,toObject) {
var output = '';
for (var i=0, l=fromObject.options.length;i<l;i++) {
output += escape(fromObject.name) + '=' + escape(fromObject.options.value) + '&';
}
alert(output);
toObject.value = output;
}


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top