0

Am using handlebar js to make a selectbox.

<select id="order_status_selection">
{{#each orders_status}} 
  <option value="{{id}}" {{#ifCond id status}} selected {{/ifCond}}> {{title}}</option>
{{/each}}
</select>

in js file am using a handlebar register

 Handlebars.registerHelper('ifCond', function(v1, v2, options) {
  if(v1 === v2) {
    return options.fn(this);
  }
  return options.inverse(this);
});

i need to add selected tag when my id == status

when i execute this code outside the selectbox (in a div) the selected tag is printing but it doesn't print inside <option></option>

Am new to handlebar any advice will be helpful

Ashith
  • 309
  • 1
  • 3
  • 17
  • Can you confirm that `id` and `status` are of the same type? – 76484 Jul 16 '16 at 12:09
  • The helper is correct, have in mind that you have `===`, instead of `==` so `v1` and `v2` should have the same time as @76484 said. Drop some console logs inside the helper and check if you're getting the correct values. – Marcos Casagrande Jul 16 '16 at 18:27

0 Answers0