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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -