jQuery: Stop decrementing textbox value if value equals 0

What I have:

I have a readonly textbox and two links. The first link increments the value of the textbox by 1 whereas the second link decrements the value by 1.

What I need:

I need the textbox value to stop decrementing at zero (I don't want negative numbers).

My code:


    jQuery(this).next(".amount input").val(parseInt(jQuery(this).next(".amount input").val())+1);

    jQuery(this).prev(".amount input").val(parseInt(jQuery(this).prev(".amount input").val())-1);

Note: .next and .prev are used because I have multiple textboxes.


<!--This block of code is occurs more than once.-->
<td class="amount">
    <a href="#" class="increment"></a>
    <input type="text" readonly="readonly" value="0" />
    <a href="#" class="decrement"></a>

A loose guess:

...with regards to decrementing...

// open onclick code here

    if (jQuery(this).prev(".amount input").val != "0"){

        // decrement code here


// close onclick code here


My working code is modelled on this Stack Overflow answer: http://stackoverflow.com/a/12209831/835950

...at which a fiddle exists for convenience: http://jsfiddle.net/iMaverick/S3PLG/2/



    var value = (parseInt($("#incdec input").val() , 10) - 1);
    $("#incdec input").val((value-1) < 0 ? 0 :(value -1));

Need Your Help

ffmpeg converting mov files to mp4


Hi i have just installed ffmpeg and i am trying to encode all my uploaded videos to .mp4 file most of the users currently upload .mov and i want to convert every video to .mp4.