javascript - How define dynamic Select Options -


i have function replace or/and populate dinamic inputs. paste 1 text in textarea , function find input referenced , add value. works fine.

bellow code:

input.addeventlistener('focus', function(){                 var content     = input.value;                 content.replace(/(\s+): ?(.+)/g, function(m, id, value) {                     var field = $('input[data-alias-import="'+id+'"]');                     var element = document.getelementbyid(field.attr('id'));                      //console.log(element.attr('id'));                     if (element) element.value = value;                 });             }); 

in case, variable input textarea.

my question is, best way make same thing select? how can find specific value in select , defined "selected".

if want selected option of select element can use jquery this:

$("#elementid :selected").val(); 

Comments