Alert in an html boot

Asked

Viewed 3,153 times

-4

hi, I have an html button and when I click on it I would like to display an Alert, how do I do this ?

follow the button code:

<input type="submit" class="btn btn-primary" id="btn_cadastro" oneclick="cadastro()"/>
  • <input type="submit" class="btn btn-primary" id="btn_cadastro" onclick="alert('alerta, yay')"/>

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()"/>

1

I believe 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()"/>

Check if your function is declared...

<script>
    function cadastro(){
       alert('Sua mensagem aqui!');
    }
</script>

1

In HTML

<input type="submit" class="btn btn-primary" id="btn_cadastro" onclick="cadastro();" />

In your Javascript

function cadastro() {
    alert("Oiii");
}

See an example working:

https://jsfiddle.net/sq9pc64j/1/

Your mistake is that you wrote onclick wrong

Browser other questions tagged

You are not signed in. Login or sign up in order to post.