0
How do I change the option
below, based on JSON return:
<select name="modalidade-frete" id="modalidade-frete">
<option value="0">0 - Por conta do emitente</option>
<option value="1">1 - Por conta do destinatário/remetente</option>
<option value="2">2 - Por conta de terceiros</option>
<option value="9" selected>9 - Sem frete</option>
</select>
Note: I wish to remove the value default 9 and change to the value corresponding to the JSON return, for example: data.mod_frete = 1
, become so:
<select name="modalidade-frete" id="modalidade-frete">
<option value="0">0 - Por conta do emitente</option>
<option value="1" selected>1 - Por conta do destinatário/remetente</option>
<option value="2">2 - Por conta de terceiros</option>
<option value="9">9 - Sem frete</option>
</select>
bfavaretto worked in parts. By using the Chrome inspector, the
option
ofvalue=9
is still selected.– lucasbento
The inspector is showing you the original HTML that the browser received. One thing is the attribute
selected
(which is in your HTML), and another is the propertyselected
(that you are accessing via JS). The attribute only sets the initial value of the property.– bfavaretto
I understood, but there’s some way to make that change, even if it’s just "visual"?
– lucasbento
You can try
removeAttribute
/setAttribute
, but I honestly don’t see any good reason to do it.– bfavaretto