I have simple
code to increment and decrement field. everything was fine but i don’t know how many field I get ( it’s generate by mvc) My question is how to smart bind two buttons for each field on page?
I tried to use $(this.id+"x").val(currentVal - 1) but it’s wrong way , I think.
Thanks for any suggestions
Additional:
- I can’t use Jquery Mobile range input.
- Text box “Text Pin #4” must be allways focused.
- All buttons must be possible to click on Mobile device.
You can select elements relative to the one that has the event triggered on it:
Here is a demo: http://jsfiddle.net/uSzr7/16/
Here is some documentation for ya:
.closest(): http://api.jquery.com/closest.prev(): http://api.jquery.com/prev.children(): http://api.jquery.com/children.val(): http://api.jquery.com/val (see the section on passing.val()a function)Another way to handle the validation is to always add or subtract one but then add a
changeevent handler to theinputelements that checks to make sure the value is valid. This helps work with native form controls since you are using thetype="number"input tag.