Reputation: 589
I want to change the selected value in the drop-down list when the page is loaded using the value in the database.
I have implemented a drop-down list using database values. It works fine. There is a column name con_s
and it has only one 1
value and all others are 0
. I have assigned it to name
attribute in <option>
. I want to selected
data which has 1
in column con_s
when the page is loaded.
I have no idea how can I do this. I have mentioned my tried code below.
Tried code:
<select id="cur_rate" @change="onChange()">
{{#each currencies}}
<option value="{{this.rate}}" name="{{this.con_s}}" selected>{{this.currency}}</option>
{{/each}}
</select>
Upvotes: 0
Views: 25
Reputation: 854
You can use build-in helper if
condition to provide the selected option. you can try like this code snippet. fiddle
<select id="cur_rate">
{{#each currencies}}
<option value="{{this.rate}}" name="{{this.con_s}}" {{#if this.con_s}}selected{{/if}}>{{this.rate}}</option>
{{/each}}
</select>
Upvotes: 1