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?

Was it helpful?

Solution

You can do this:

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top