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?
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?
You can separate the commands in onclick
through ;
<input type="button" value="click me" onclick="alert('alerta1'); alert('alerta2');" />
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();" />
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
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();" />