How to assign single or multiple values to select2?
I use below:
<label for="input-fruits_liked">Assignment Method</label>
<select class="form-control select2" id="fruits_liked" name="fruits_liked" multiple="multiple">
<option value="0">None</option>
<option value="1">Orange</option>
<option value="2">Apple</option>
<option value="3">Grape</option>
<option value="4">Banana</option>
</select>
<script type="text/javascript">
$("#fruits_liked").val('@Model.fruits_liked').trigger('change');
</script>
I have tried the above, it returns Uncaught ReferenceError: $ is not defined
the value of model.fruits_like is something like the following:
fruits_like ": "[\"Apple\", \"Banana\"]
Anybody has experienced with this before?
Thank you so much in advance. Dd