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

Q1396 How can I pass the values of a selected options to another select form field and then submit them all of form submission?

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

Q1396 How can I pass the values of a selected options to another select form field and then submit them all of form submission?

Several things:

  • The select form field should have a name.
  • The select form field should possibly be a muliti select form field.
  • For the entries to be passed in the form submission the entries must be SELECTED!

Try:

<script language="JavaScript"><!--
function transfer() {
    var defaultSelected = true;
    var selected = true;
    var optionName = new Option(document.leftForm.leftSelect.options[document.leftForm.leftSelect.selectedIndex].text,
                                document.leftForm.leftSelect.options[document.leftForm.leftSelect.selectedIndex].value,
                                defaultSelected, selected)
    var length = document.rightForm.rightSelect.length;
    document.rightForm.rightSelect.options[length] = optionName;
    history.go(0);
}
//--></script>

<table><tr><td>

<form name="leftForm">
<select name="leftSelect">
<option value="1">one
<option value="2">two
</select>

<input type="button" value="Transfer" onClick="transfer()">
</form>

</td><td>

<form name="rightForm">
<select name="rightSelect" multiple>
</select>
<input type="submit" value="Submit"
</form>

</td></tr></table>

Note the above will not work in Internet Explorer 3, as it does not support the addition of options to a select form field.

Feedback on 'Q1396 How can I pass the values of a selected options to another select form field and then submit them all of form submission?'


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.