Can I use onclick twice? [duplicate]

-2

I have a button and on it I need to use onclick to trigger the (this) function for the javascript but I need to put sound on the button, what do I do?

    
asked by anonymous 26.06.2017 / 20:49

4 answers

6

You can separate the commands in onclick through ;

<input type="button" value="click me" onclick="alert('alerta1'); alert('alerta2');" />
    
26.06.2017 / 20:57
0

Put a function to run onClick with whatever procedures you want ... ex:

<script>
  function onClickBotao() {
    alert('faz algo');
    alert('faz outra coisa');
  }

</script>
<input type="button" value="click me" onclick="onClickBotao();" />

link

    
26.06.2017 / 21:23
0

You can invoke your function as a function:

JS:

function minhaFuncao1() {
//Fazer alguma coisa aqui
   minhaFuncao2(); // chamar função "minhaFuncao2"
}

function minhaFuncao2() {
 // tocar som
}

Html:

<button onclick="minhaFuncao1()">Click</button>

More detail: link

    
26.06.2017 / 21:33
0

You can simply make the two calls you need within your onClick, so you would have both the method needed along with the method that will play the sound you want, something like:

<input type="button" value="click som" onclick="metodo1(); metodoSom();" />
    
26.06.2017 / 22:47