Assuming I have understood right, which is to change the value just by clicking, you can do something very practical with Javascript:
function spin(element,delta,max) {
var input = element.parentNode.children[1];
var val = parseInt( '0' + input.value) + delta;
if(val<0) val = 0;
if(val>max) val = max;
input.value = val;
}
<div>
<button onclick="spin(this,-1,7)">-</button>
<input name="bacalhau" value="0">
<button onclick="spin(this,1,7)">+</button>
Pudim de bacalhau
</div>
<div>
<button onclick="spin(this,-1,10)">-</button>
<input name="sopa" value="0">
<button onclick="spin(this,1,10)">+</button>
Sopa de graviola
</div>
<div>
<button onclick="spin(this,-1,4)">-</button>
<input name="costela" value="0">
<button onclick="spin(this,1,4)">+</button>
Costelinha de polvo
</div>
Thus, one can either type, or simply click on - and + to change the value.
The created function has 3 parameters, the first is the this
so that the function "know" which was the item clicked, the second is how much to add to each click (or decrease, if negative) and the third is the maximum possible of that field, when clicking the button.
If you change the HTML structure of div
, just adjust the content in children[1]
to reflect the correct input position.
This is an initial draft, but it’s a good starting point. Then you can augment with CSS, and improve the function to better integrate with HTML5 validation, or any necessary customizations.
An idea would be to use buttons that add a variable that is shown in the text field.
– mutlei
Could you show me an example in code ? @mutlei
– allan araujo
It is not much easier to put a spinner, or a boot + and - instead of checkbox?
– Bacco
@Bacco how could I do ? I would be grateful to put up the answer is that I will use this project only on localhost/tablet
– allan araujo