I am assuming the html looks something like this:
<input type="text" id="item_count" value="0" />
<input type="button" id="btn" value="Increment"/>
You'll need an event handler for clicks on the button (obviously), and an event handler for the change event on the input field. The click on the button will not trigger the change event, but changing the input field manually will. Therefore we can safely reset the counter to 0 if the user alters the field.
$('#btn').on( 'click', function() {
$('#item_count').val( function( i, oldval ) {
return (oldval*1) + 1;
} );
} );
$('#item_count').on( 'change', function() {
$('#item_count').val( '0' );
} );
Edit: There are only two ways of entering data. One is by keyboard. The other one is by the button. That means that if the change event isn't triggered by the button, 100% of the cases where the change event is triggered, it must be via the keyboard. You can alter the code a bit to include the .data(...)
(docs) functionality of jQuery and do something like the following code. It will reset the input when it was altered, and subsequently the button was pressed.
$('#btn').on( 'click', function() {
$('#item_count').val( function( i, oldval ) {
if( $(this).data( 'fromKeyboard' ) == 1 ) {
$(this).data('fromKeyboard', 0 );
return 1;
}
return (oldval*1) + 1;
} );
} );
$('#item_count').on( 'change', function() {
$(this).data( 'fromKeyboard', 1 );
} );
Example on jsbin.