Ofir Attia
Ofir Attia

Reputation: 1275

Deleting from Multiple Select list

I need to delete an item from a multiple list using jQuery

HTML:

<input type="checkbox" id="theCheckbox"/>
<select id="theSelect" multiple="multiple">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

JavaScript:

$("#theCheckbox").change(function() {
    $("#theSelect").attr("multiple", (this.checked) ? "multiple" : "");
}).change();

This is the example.

This is my code form my project. if you can implement on this code i will be glad! My Code

Upvotes: 0

Views: 182

Answers (3)

Parv Sharma
Parv Sharma

Reputation: 12705

$('#theSelect').change(function(){
    var selectedIndex = $(this)[0].selectedIndex;
    //alert(selectedIndex);
    var selected = $(this).children("option").eq(selectedIndex);
    selected.remove();
});
$("#theCheckbox").change(function() {
    $("#theSelect").attr("multiple", (this.checked) ? "multiple" : "");
}).change();​

Upvotes: 0

Sender
Sender

Reputation: 6858

Deleting Multiple Select list see this Edit

Both Condition Work.

$("#theCheckbox").change(function() {
    $("#theSelect").attr("multiple", (this.checked) ? "multiple" : "");
}).change();

$('a').click(function() {
    $('#theSelect option:selected').remove();
});

Upvotes: 0

Richard Dalton
Richard Dalton

Reputation: 35803

Just select the option you want to delete and call the remove() function on it:

$('#theSelect option:eq(1)').remove();

http://jsfiddle.net/DdhSF/162/

Upvotes: 2

Related Questions