jQuery Dropdown set Value

drop-down-menu, jquery, jquery-ui

Solution

If you wrapped your `select` in a jquery-ui `autocomplete` widget :

The original selects will be hidden, the displayed html is an input.

You need to also set the value of this input :

function(){
    var newval = $('#drop_1').val();

    $('#drop_2').val( newval );
    //you will have to find the correct selector for your particular settings here.
    //I base this code on the jquery-ui demo (see link below) :
    var $input = $('#drop_2').sibling('span.ui-combobox').find('input');
    $input.val(newval);
}

jquery-ui demo for combobox widget

Problem

i have a JQuery UI dropdown. Actually i have 2. I select in the first one something, set a checkbox on true. In the .change() of that checkbox i want to copy the selected value from the first dropdown to the second one. with `$('#drop_1').val()` i get the selected value. i thought i can set it with `$('#drop_1').val($('#drop_2').val())`. Sadly this only works with normal dropdowns. Is there a way to set the value like this: ``` $('#drop_1').find('option:selected').text(); ``` Any idea how can i do this? This did the trick and it works now. The value was set, but it wasnt shown in the UI. ``` var selected_campaign = $('#campaign_id').val(); $('#follow_campaign_id').val(selected_campaign); $('#follow_campaign_id').next().find('input.ui-combobox-input').val($('#follow_campaign_id').children('option[value=' +selected_campaign+ ']').html()); ``` FIXED

Original source

Related problems