javascript - Meteor - update var on select change -
i've got dropdown, when user select value, want code executed. question: how can check whether selected value of dropdown has changed?
in html file:
<template name="jaren"> <form id="yearfilter"> <select class="selectpicker span2" id="yearpicker" > {{#each jaren}} {{#if selectedyear}} <option selected value="{{_id}}">{{jaar}} {{description}}</option> {{else}} <option value="{{_id}}">{{jaar}} {{description}}</option> {{/if}} {{/each}} </select> </form> </template>
in javascript file:
template.jaren.jaren = function() { return years.find(); } template.jaren.selectedyear = function() { if (session.get('year_id') == this._id) { return true; } else { return false; } } template.jaren.events({ 'change form#yearfilter #yearpicker': function(event, template) { session.set('year_id', template.find('#yearpicker').value); console.log("value changed"); } });
you can value of select element inside event handler , compare old value had stored:
"change #yearpicker": function(evt) { var newvalue = $(evt.target).val(); var oldvalue = session.get("year_id"); if (newvalue != oldvalue) { // value changed, let's } session.set("year_id", newvalue); }
Comments
Post a Comment