javascript - Semantic UI: How to define selected item of search dropdown ("<select>")? -
how can set selected item of search dropdown (select) form field? tried 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: base semantic ui frontend framework ;-)
for semantic ui framework, should consult guide here: dropdown behavior. tells make following call:
$('#dropdown').dropdown('set selected', value);
or pass object (perhaps useful multiple select or developer's preference):
$('#dropdown').dropdown({'set selected': value});
non-framework answer (before question edited specific framework)
if select list has id of dropdown
, can do:
$('#dropdown').val();
to set value, option has value of a
, can do:
$('#dropdown').val('a');
i suggest reading jquery page on .val().
jsfiddle example: http://jsfiddle.net/vo9kpsry/1
Comments
Post a Comment