-2
I have a button and in it I need to use onclick to trigger the function (this) for javascript but I need to put sound on the button, what I do ?
-2
I have a button and in it I need to use onclick to trigger the function (this) for javascript but I need to put sound on the button, what I do ?
6
You can separate the commands on onclick
through the ;
<input type="button" value="click me" onclick="alert('alerta1'); alert('alerta2');" />
It didn’t work, he just said
0
Put a function to be executed in onClick with the procedures you want... ex:
<script>
function onClickBotao() {
alert('faz algo');
alert('faz outra coisa');
}
</script>
<input type="button" value="click me" onclick="onClickBotao();" />
It is already like this, but in onclick I need to trigger this too, and the 2 together do not work
This one you need to use is to reference the object that was clicked? because it could modify the code by passing this in the call: onClickBotao(this)
and accepting an argument in the function: function onClickBotao(elemento){
 alert(elemento.value);
 }

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: https://www.w3schools.com/js/js_function_invocation.asp
It would be great however as I call the sound logo in html and n in javascript understands ?
0
You can simply make the two calls you need inside your onClick, so you would have both the required method along with the method that will play the sound you want, something like:
<input type="button" value="click som" onclick="metodo1(); metodoSom();" />
Browser other questions tagged javascript html onclick
You are not signed in. Login or sign up in order to post.
Why don’t you use
click
jquery ?– Matheus Miranda
I don’t know how to use Jquery .
– Fabiana Fernandes
It would be easier for you to put your little code, so the stackoverflow guys understand better
– Matheus Miranda