Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Form | 10.1 | Q218 [ previous next ]

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>

©2018 Martin Webb