Scrivi il limite inferiore nell'input
aggiungi un terzo parametro alla funzione che indica qual è la quantita sotto la quale non si deve scendere
codice:
<head>
<script>
function $(id) {
return document.getElementById(id);
}
function addPieces(campo, by, limite_inferiore) {
var pezzi = campo.value;
pezzi = parseInt(pezzi, 10);
if (isNaN(pezzi)) pezzi = 0;
pezzi += by;
if (pezzi < limite_inferiore) return;
campo.value = pezzi;
}
</script>
</head>
<input type="text" id="articoli" readonly="readonly" value="40"/>
<input type="button" value="+" onclick="addPieces($('articoli'), 10, 40)" />
<input type="button" value="-" onclick="addPieces($('articoli'), -10, 40)" />
Ciao