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

Q218 How can I copy multiple options from one options list to another?

irt.org | Knowledge Base | JavaScript | Form 10.1 | Q218 [ previous next ]

Q218 How can I copy multiple options from one options list to another?

The following will work in Netscape Navigator 3, Netscape Navigator 4 and Internet Explorer 4:

<script language="JavaScript"><!--
function populateForm() {
    for (var Current=0;Current < document.formName.selectName1.options.length;Current++) {
        if (document.formName.selectName1.options[Current].selected) {
            var defaultSelected = true, selected = true;
            var optionName = new Option(document.formName.selectName1.options[Current].value, document.formName.selectName1.options[Current].text, defaultSelected, selected)
            if (replacedfirst)
                var length = document.formName.selectName2.length;
            else
                var length = 0;
            document.formName.selectName2.options[length] = optionName;
            replacedfirst = true;
        }
    }
}

var replacedfirst = false;
//--></script>

<form name="formName" onSubmit="return false;">
<select name="selectName1" multiple size="3">
<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>

<input type="button" value="Enter" onClick="populateForm()">

<select name="selectName2" multiple size="3">
<option value="">           
</select>
</form>

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.