How to get value of an input text


#1

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?


#2

You can use jQuery like $('#qty').val()


#3
$(event.currentTarget).val()

#4

@chenroth this will just get the value of the button


#5

Ok I found the answer it should be

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

You can see here the documentation about template.find()
Also posted it in stackoverflow and got the answer :slight_smile:


#6

right
sorry, I haven’t noticed that detail