Hi Guys,
Newbie here...
Am looking forward to populate a list from a dropdown list into a multiselect list.
Any idea now how am gonna get it done?
Thanks...

Dani AI

Generated

A reliable pattern is to handle the dropdown's change event, take the selected <option>, and append a clone into the multi-select (or remove it from the source if you want to "move" rather than "copy"). Keep unique value attributes so duplicates can be detected and skipped. As requested, the most helpful details to include when asking for code are the HTML for both selects (IDs), whether options come from the server or are static, the desired copy-or-move behavior, and the jQuery version.

Example (minimal):

<select id="single">
  <option value="">--choose--</option>
  <option value="1">One</option>
  <option value="2">Two</option>
</select>

<select id="multi" multiple size="6"></select>

<script>
$('#single').change(function(){
  var $sel = $(this).find('option:selected');
  var val = $sel.val();
  if (!val) return;
  if ($('#multi option[value="' + val + '"]').length === 0) {
    $('#multi').append($sel.clone().prop('selected', true));
  }
});
</script>

Notes: ensure the target has the multiple attribute, use .clone() to keep the original in place or .remove() to move it, and test duplicate detection against value. For server-driven lists build <option> elements before appending. See the HTML select reference on MDN (select element) and jQuery's DOM insertion methods (append) for details.

Recommended Answers

All 2 Replies

Member Avatar for Member #949455

Am looking forward to populate a list from a dropdown list into a multiselect list.

Can you at least post a code of what you have done?

okay

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.