How to make a submit that zeroes a counter

0

I do not understand javascript and not to know how to search to make a button that when tight zerosse my counter which is a global variable

<form id="btn" method="get">
<input type="submit" name="submit" value="zerar"onclick="submit();">
</form>
<script>
    function ssubmit(){
         document.getElementById("btn".submit());
    }
</script>
  

so he calls another function that would reset the variable "num"   where do I put in to call the other function?

    
asked by anonymous 17.11.2018 / 21:12

1 answer

0

Do you really need the button to be a submit? Because you can control the click on any element for this. Anyway, go ahead.

<form id="btn" method="get">
  <input type="submit" name="submit" value="zerar" onclick="ssubmit();">
</form>
<script>
    function ssubmit(){
         num = 0; //assumindo que seja num a variável global zerada
         document.getElementById("btn".submit()); //procede o submit normal do formulário (isso vai recarregar a página, daí perde o sentido o código).
    }
</script>

If you want to have the function call instead of submit , you can do the following:

<button onclick="ssubmit();">Zerar</button>
<script>
    function ssubmit(){
        num = 0; //de novo, assumindo que num seja a variável global
        outraFuncao(); // chama uma outra função para fazer seja lá o que você quiser fazer
    }
</script>

If I did not answer your question, explain what you need best.

    
17.11.2018 / 23:48