I have a quantity variable, and I have two tags <a>
that function as onclick
and call the function myFunc1
or myFunc2
. One serves to increase the amount and another to decrease. to myFunc1 to decrease and to myFunc2 to increase.
<a onclick='myFunc1()' style='font-size:18px' id='diminuir' class='fa'></a>
<script type="text/javascript">
function myFunc1() {
var oldValue = <?php echo json_encode($quantidade)?>;
if (oldValue > 0) {
var newVal = parseFloat(oldValue) - 1;
} else {
newVal = 0;
}
<?php echo json_encode($quantidade)?>; = newVal;
}
function myFunc2() {
var oldValue = <?php echo json_encode($quantidade)?>;
var newVal = parseFloat(oldValue) + 1;
<?php echo json_encode($quantidade)?> = newVal;
<?php echo json_encode($quantidade)?>; = newVal;
}
</script>
I want the tags to increase and decrease the variable amount, and from what I've seen the only way I've seen to do this is with onclick, and to do the function I want to pass the variable quantity that is php, increase it with javascript and back to convert it to php
But this code is not working, is the problem of differentiating variables, tag or anything else?