Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a function from a HTML button

I wonder what I am doing wrong in this case? I got this button which is an HTML element. When I click on it, I want the function push() to get activated. Unfortunally my console says:

ReferenceError: push is not defined

Can some one help me in this case? Thanks so much!

<button type="button" onclick=push()>Click Me!</button> 
<script type="text/javascript">
function push (){.....};
</script>
like image 985
Suppe Avatar asked Aug 07 '17 21:08

Suppe


People also ask

How do you call a script when a button is pressed HTML?

Use the onclick attribute to execute a script when the element is clicked in HTML.


1 Answers

You can change onclick=push() to onclick="push()" to make it work!

Also, there might be something wrong in the body of the push function because of which it is not able to compile - hence, the error.

like image 61
Sanjay Rathod Avatar answered Oct 04 '22 21:10

Sanjay Rathod