yammat/static/js/crementing.js
s72785 8155a49cf7 prevent NaN fixes usability glitch
deleting content of input field results in not useable UI
2015-05-29 00:06:19 +02:00

12 lines
607 B
JavaScript

/*
this is thought for (de-/in)crement integer values in (e.g. input) form elements
calling like
<input type="input" value="++" onclick="crmnt(document.getElementById('id'),1)" />
<input type="input" value="+=5" onclick="crmnt(document.getElementById('id'),5)" />
<input type="input" value="-=5" onclick="crmnt(document.getElementById('id'),-5)" />
<input type="input" value="--" onclick="crmnt(document.getElementById('id'),-1)" />
*/
function crmnt( e, i ) { /* read: in-/decrement ( dom-element, signed-integer ) */
var d = parseInt( e.value ) + i;
e.value = ( d <= 0 || isNaN(d) )? 0 : d;
}