Search code examples
meteoriron-router

Redirect on select option with meteor


I need some help with meteor. I've template with select options:

<select id="collapseFour" class="form-control collapse">
  {{#each examNum}}
    <option>{{this}}</option>
  {{/each}}
</select>

And I've helper that helps me in creating list of exam numbers:

Template.adminLayout.helpers({
  examNum: function() {
    var number = [];
    for(var i=1;i<=50;i++){
      number[i] = i;
    }
    return number;
  }  
});

I need to make page redirect to the specified exam page, when I choose one of the options. Like onchange, or href in a tag element. I know that it can be solved with helpers, so tried this:

Template.adminLayout.helpers({
  'change [type=select]': function(e,t){
    // page redirect
  },
});

But it doesn't work. What can choose the problem, any help will be appreciated!


Solution

  • Already solved, just in case if somebody needs. Here is the template:

    <select id="collapseFour" name="examNo" class="form-control collapse">
      {{#each examNum}}
        <option value="{{this}}">{{this}}</option>
      {{/each}}
    </select>
    

    Js file:

    Template.adminLayout.events({
      'change #collapseFour': function(event, template) {
        no = template.find('[name=examNo]').value;
        Router.go('adminExamPage', {no: no});
      }
    });
    

    And router.js:

    this.route('adminExamPage',{
        path: '/coordinator/exam/:no',
        layoutTemplate: 'adminLayout'        
    });