I am creating a form where the user can add and subtract from the value of the input field in this case to display a number of children.
Naturally I can add and subtract from the number which displays on my screen, however the actual value stays the same at 0 when I check in console. It is important for me to be able to check this value so I can set a minimum and a maximum amount.
How do I make sure the value changes on click of my buttons?
JS:
childVal = $('#pageSearch-children').val();
minValueChild = $('#pageSearch-children').attr('min');
maxValueChild = $('#pageSearch-children').attr('max');
if (childVal < maxValueChild) {
$('.add').click(function () {
$('#pageSearch-children').val( function(i, oldval) {
return ++oldval;
});
$('#pageSearch-children').val() + 1;
});
}
if (childVal > minValueChild) {
$('.sub').click(function () {
$('#pageSearch-children').val( function(i, oldval) {
return --oldval;
});
$('#pageSearch-children').val() - 1;
});
}
HTML:
<h3 class="white black">
<input class="backgroundNoneInput" type="number" value="0" id="pageSearch-children" name="children" min="0" max="{{ $property--property_sleeps or '99' }}">
</h3>
<button type="button" class="sub backgourndNoneButt">
<span class="white fa fa-minus fa-2x faPlusMin" aria-hidden="true">
</span>
</button>
<button type="button" class="add backgourndNoneButt">
<span class="white fa fa-plus fa-2x faPlusMin" aria-hidden="true">
</span>
</button>