rtown
06-26-2012, 07:01 PM
Hey everyone,
Need a hand with a little JS. The script below that adds and subtracts by 1, to a value already given.
<input type="text" name="TransNumber" id="TransNumber" size="5" value="0001" readonly="readonly" class="readonly">
<input type="button" value="+" style="width:23px" onclick="Number(document.getElementById('TransNumber').value++)" >
<input type="button" value="-" style="width:23px" onclick="Number(document.getElementById('TransNumber').value--)" >
The existing value has leading zeros such as 0001. When you add or subtract the leading zeros disappear. I tried to tie a zero padding function into the onclick but this does not work.
I would also like to disallow subtracting past 0001. So, 0000 and negative number should not be allowed.
Any advice appreciated! Thanks.
:D
Need a hand with a little JS. The script below that adds and subtracts by 1, to a value already given.
<input type="text" name="TransNumber" id="TransNumber" size="5" value="0001" readonly="readonly" class="readonly">
<input type="button" value="+" style="width:23px" onclick="Number(document.getElementById('TransNumber').value++)" >
<input type="button" value="-" style="width:23px" onclick="Number(document.getElementById('TransNumber').value--)" >
The existing value has leading zeros such as 0001. When you add or subtract the leading zeros disappear. I tried to tie a zero padding function into the onclick but this does not work.
I would also like to disallow subtracting past 0001. So, 0000 and negative number should not be allowed.
Any advice appreciated! Thanks.
:D