Trung Tran
Trung Tran

Reputation: 13771

Wrong option value selected in meteor javascript

I am building an app in Meteor and I am having trouble returning the value of a dropdown list. I have a page that has more than 2 rows where each row has a dropdown list. If I pick a value from the dropdown list in the SECOND row, my app returns the value from the FIRST dropdown list. The same issue occurs if I pick a value from any dropdown list other than the first row. It will return the value from the dropdown list in the first row. Here is my template:

<td>
<select id="clientsSelect" name="clients">
    <option disabled selected> Select Client </option>
    {{#each users}}
        <option value="{{this._id}}">{{this.profile.companyName}}</option>
    {{/each}}
</select>
</td>

Here is my templates.js

Template.adminTemplates.events({
    "change #clientsSelect": function(event, template){
        var selectValue = template.$("#clientsSelect").val(); //grab value of dropdown list
        console.log(select val: ' + selectValue); //always returns value of the FIRST dropdown list
    }
});

Upvotes: 0

Views: 159

Answers (1)

Jordan Davis
Jordan Davis

Reputation: 1337

You just need to get the value with event.target.val() so the value comes from the same element that was clicked. There's more info in the docs.

Upvotes: 1

Related Questions