Alert in an html button

-4

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()"/>
    
asked by anonymous 26.10.2018 / 20:34

3 answers

1

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()"/>
    
26.10.2018 / 20:40
1

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>
    
26.10.2018 / 20:43
1

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:

link

Your mistake is that you wrote wrong onclick

    
26.10.2018 / 20:44