Skip to content

Instantly share code, notes, and snippets.

@adamthedeveloper
Created November 19, 2013 00:59
Show Gist options
  • Save adamthedeveloper/7538338 to your computer and use it in GitHub Desktop.
Save adamthedeveloper/7538338 to your computer and use it in GitHub Desktop.
Increment / Decrement coffeescript
window.ChangeQuantity ||= {}
ChangeQuantity.load = ()->
$("input.change-quantity").click((evnt)->
evnt.preventDefault()
quantityField = $(this).parent().find('input.quantity')
currVal = parseInt(quantityField.val())
if $(this).val() == '+'
quantityField.val(currVal+=1)
else
if currVal > 0
quantityField.val(currVal-=1)
)
@adamthedeveloper
Copy link
Author

Here's the html:

<div class="select-quantity">
  <input class="change-quantity less" type="button" value="-">
  <div class="input string optional order_quantity">
    <label class="string optional control-label" for="order_quantity">Quantity</label>
    <input class="string optional qty quantity" id="order_quantity" name="order[quantity]" size="50" type="text" value="0">
  </div>
  <input class="change-quantity more" type="button" value="+">
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment