Is it possible to copy a selected option from the first dropdown to another using Jquery and disallowing the user from copying the SAME option ?
HTML Markup
<select id="one" multiple="multiple">
<option>one</option>
<option>two</option>
<option>three</option>
</select>
<select id="two" multiple="multiple">
</select>
Jquery
$('#one option').click(function() {
$(this).clone().appendTo("#two");
});
Yes:
var option = $("#idOfSelect option:eq(0)"); //eq 0 targets the first option, change to what you need
$("#idOfOtherSelect").append(option);
Like this:
$('#first').change(function(){
$('#second').append("<option value="+$(this).val()+">"+$("#first option:selected").text()+"</option>")
})
Example:
$("#copy").on("click", function(e) {
e.preventDefault();
$("#select1 option:selected").clone().appendTo($("#select2"));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.