")? How can I set the selected item in the drop-down list box (select)? ...">

Semantic interface: how to determine the selected search element ("<select>")?

How can I set the selected item in the drop-down list box (select)? I tried it with the following jQuery / JavaScript code:

if (equal == 0) { $('#sj_company').html($('#sj_company').html() + '<option value="' + key + '" selected="selected">' + data[key] + '</option>'); $('.searchdropdown').dropdown('set selected', data[key]); } else { $('#sj_company').html($('#sj_company').html() + '<option value="' + key + '">' + data[key] + '</option>'); } 

Edit: The foundation is the semantic structure of the ui interface, -)

+7
javascript semantic-ui
source share
2 answers

My mistake: I initialized the semantic interface popup to . I uploaded the dropdowns via AJAX. Solution: Initialize Dropdown AFTER the AJAX boot process.

+1
source share

For the scope of the semantic interface, you should refer to the manual here: pop-up behavior . This tells us to make the following call:

$('#dropdown').dropdown('set selected', value);

Or pass in an object (perhaps useful for multiple choice or for developer preference):

$('#dropdown').dropdown({'set selected': value});

Answer without frame (before the question was edited for a specific structure)

If the say dropdown id is on the selection list, you can do:

$('#dropdown').val();

To set a value, say the option has a value of a , you can do:

$('#dropdown').val('a');

I suggest reading the jQuery .val () page.

JSFiddle example: http://jsfiddle.net/vo9kpsry/1

+17
source share

All Articles