Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q556 Is it possible to transfer an "option" item from dropdownlist A to dropdownlist B?

irt.org | Knowledge Base | JavaScript | Form 4 | Q556 [ previous next ]

Q556 Is it possible to transfer an "option" item from dropdownlist A to dropdownlist B?

Internet Explorer 3 does not support the addition and removal of options from drop down boxes, but apart from that try:

<script language="JavaScript"><!--
function transferOption(object) {
    var index = object.dropdownlistA.selectedIndex;
    if (index > -1) {
        var newoption = new Option(object.dropdownlistA.options[index].text, object.dropdownlistA.options[index].value, true, true);
        object.dropdownlistB.options[object.dropdownlistB.length] = newoption;
        if (!document.getElementById) history.go(0);
        object.dropdownlistA.options[index] = null;
        object.dropdownlistA.selectedIndex = 0;
    }
}
//--></script>

<form name="formName">

<select name="dropdownlistA">
<option value="Option 0">Entry 0
<option value="Option 1">Entry 1
<option value="Option 2">Entry 2
<option value="Option 3">Entry 3
<option value="Option 4">Entry 4
<option value="Option 5">Entry 5

</select>
<select name="dropdownlistB">
</select>

<p>

<input type="button" value="Transfer"     onClick="if (document.images) transferOption(this.form)">

</form>

Feedback on 'Q556 Is it possible to transfer an "option" item from dropdownlist A to dropdownlist B?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.