Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone html select value

I have a form that is bound to a model: user form, which is represented by Backbone.View.extend which has:

model:user

inside the view:

events: {
   'click #payment' : 'updatePayment'
}

where payment is a html select with :

<div class="span2" id="payment">
    <select class="span12">
         <option value="paypal">paypal</option>
         <option value="check">check</option>
    </select>
</div>

updatePayment: function() {
    var payment = this.$("#payment");
    console.log(payment);
}

Sadly payment has no value. Can someone please help? Thanks!

like image 285
royB Avatar asked Apr 07 '13 20:04

royB


1 Answers

It is a bit hard to tell... but it seems like you want this:

events: {
   'change .span12' : 'updatePayment' // listen for change of <select> element.
},

updatePayment: function(event) {
    var payment = event.target.value;
    console.log(payment); // print 'paypal' or 'check'.
}
like image 189
Paul Hoenecke Avatar answered Sep 30 '22 19:09

Paul Hoenecke