Question

I have a select list which is dynamically populated, and an insert button. When I click an option in the select list and then click the insert button, a popup opens. In the popup there is a text field where I insert a value and click the OK button of the popup. Now I want that when I click OK, the popup value should be inserted before the selected option of the select list.

/*  Please show some example Code Here  */

How do I do this?

Était-ce utile?

La solution

You can do this:

$('#mySelect option:selected').before($('<option>', {
    value: 1,
    text: 'My option'
}));

Autres conseils

try

var sel = opener.document.getElementById("someSelect");
sel.options[sel.selectedIndex-1].option=new Option("some text","some value");
$('#ddlWeeklyWeightIn').on("change", function () {
           $("#ddlWeeklyWeightIn option:selected").insertBefore($("#ddlWeeklyWeightIn option:selected").prev());
        });

See Demo

Hope It helps you.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top