I am using the model MVC
with PHP v7.
, HTML5
and SQL server 2008
, I have a page where I display a certain list and for each record I have a button to update.
Pressing the button calls a function in JS
, which through AJAX
, brings the information to be updated in a form. In the form I have a SELECT
where I want to load the information, this shows the option with which I saved before.
I have made the loading with several options, but only if I open the SELECT
the selected option appears but it is not shown in the SELECT
, it is only shown if I deploy it.
I used the following code Jquery
:
$("#field option[value="+info+"]").attr("selected", "selected");
$("#field option[value="+info+"]").attr("selected", true);
$("#field").val(info.trim()).attr('selected', "selected");
$('select[name="field"]').find('option[value='+info+']').attr("selected", true);
document.querySelector('#field-8 [value="' + info + '"]').selected = true;
All if you select the value they should but in the text is not displayed.
Example that if you select the option you should:
But when loading the information that must be updated, it appears: