I have a select2 drop down and would like to know the best way to SET a VALUE if the OPTION selected == " Apple" for instance.
Here is my Select2
<select id="fruit" title="fruit" name="fruit"
class="form-control select2-single">
<option value=""> </option>
<option value="">Apple</option>
<option value="">Lemon</option>
</select>
What I'd like to achieve is:
If Option "Apple" is selected, SET Value to THISVARIABLE (I get responses from an AJAX Post and would like to dynamically set the Value
This small example might give you something to study.
The first select is like your AJAX, and it sets a variable. It then uses that variable to set the value of a second drop-down.
Note: To set the value of a Select/dropdown, set the value of the Select element to be the value of the desired option. Thus, every option should have a "value".