Chris Ian
Chris Ian

Reputation: 771

MeteorJS: How to get value of an input text

I have this code:

product.jade

template(name="product")
    label(for="qty") Qty:
    input#qty.form-control(type="text", value="1", name="qty")
    button.btn.btn-default.addcart Add to Cart

product.coffee

Template['product'].events
  'click .addcart': (event, template) ->
    ????

How do I get the value of input text qty? I tried the event variable but its limited in the button. Any ideas?

Upvotes: 1

Views: 654

Answers (1)

255kb - Mockoon
255kb - Mockoon

Reputation: 6974

Considering your code you can get the value like this:

'click .addcart': (event, template) ->
    qty = template.find('#qty').value;

You can see here the documentation about template.find().

But if you have a submit event on your <form> you can also do this:

'submit .your-form': (event, template) -> 
    qty = event.target.qty.value //qty = name of the field

Upvotes: 2

Related Questions