I’m using this code
<a id="minus" href="#">-</a>
<span id="VALUE">0</span>
<a id="plus" href="#">+</a>
Javascript:
$(function(){
var valueElement = $('#VALUE');
function incrementValue(e){
valueElement.text(Math.max(parseInt(valueElement.text()) + e.data.increment, 0));
return false;
}
$('#plus').bind('click', {increment: 1}, incrementValue);
$('#minus').bind('click', {increment: -1}, incrementValue);
});
to have a plus/minus incrementator of the filed named “VALUE”.
Now, i have a form using this containing 150 field like this… there’s a way to generalize this code passing in some way to the function the name of the field that the user is incrementing/decrementing?
Otherwise, i have to replicate this code 150 times…
try this one if this helps:
i have changed a little bit i used
classes .plus, .minusinstead ofids #plus, #minuscheck this out in fiddle: http://jsfiddle.net/L2UPw/