I’ve searched all around for a solution and have found nothing. Here is some sample code:
$('#myselect').append(
'<option id=\'myoption\'></option>'
);
$('#mytextfield').change(function() {
$('#myoption').html($(this).val);
});
so, i want to change the select option’s html whenever my text field is changed. any ideas?
thanks!
Apart from the missing
()onval, writinginnerHTMLof an<option>is generally unreliable due to how browsers implement form fields, and writing theinnerHTMLof anything from user input is highly inadvisable—what if the user typed something with<or&symbols in?Use the standard DOM
textproperty to change the label text instead, eg.:(or
$(this).val()if you must, but I think the plain-DOM version is more readable.)