How to make a Submit that Zera an accountant

Asked

Viewed 108 times

0

I don’t understand javascript and I don’t know how to search to make a button that when pressed zeroes my counter that 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>

then he calls another function that resets the variable "in" where I put to call the other function?

  • What variable? Could you provide a slightly more detailed code example?

  • hi, so the variable is even a normal integer - >int num = 3; , and it sits there at the top of the code.

  • i am working with Andy on a college project, and are 3 blocks the entries, html, and counter function + reset

1 answer

0


Do you really need the button to be a Submit? Because you can control the click on any element for that. Anyway, it follows.

<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>

Already in case you want instead of submit, happen only the function call, you can do:

<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 haven’t answered your question, explain better what you need.

  • Hi friend, I gave another way, work with Rduino is very confusing and I have other work to do u.u I made a function that reads the url and when this happens enters my if and Zera, there are some bugs, but ta working xD Thanks anyway

Browser other questions tagged

You are not signed in. Login or sign up in order to post.