Hello, I have a button in html and when I click on it I would like to display an alert, how do I do that?
follow the button code:
<input type="submit" class="btn btn-primary" id="btn_cadastro" oneclick="cadastro()"/>
Hello, I have a button in html and when I click on it I would like to display an alert, how do I do that?
follow the button code:
<input type="submit" class="btn btn-primary" id="btn_cadastro" oneclick="cadastro()"/>
Your button is right, you just need to change the oneclick to onclick.
See the code below:
function cadastro(){
alert('ok');
}
<input type="submit" class="btn btn-primary" id="btn_cadastro" onclick="cadastro()"/>
I think your syntax is incorrect the function call should be "onclick" and not "oneclick" see:
<input type="submit" class="btn btn-primary" id="btn_cadastro" onclick="cadastro()"/>
Make sure your role is declared ...
<script>
function cadastro(){
alert('Sua mensagem aqui!');
}
</script>
No HTML
<input type="submit" class="btn btn-primary" id="btn_cadastro" onclick="cadastro();" />
In your JavaScript
function cadastro() {
alert("Oiii");
}
See an example working:
Your mistake is that you wrote wrong onclick