Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button onclick not calling function

My button code looks like this:

<button onclick="submitFunction()">Submit</button>

And my function code like this:

function submitFunction() {
    alert("example");
}

I've been looking online for an answer and tried a bunch of things, but nothing seems to work. I'm just putting the alert there to see if the function is being called at all. I'm using the following to link the files.

<script src="file.js"></script>
like image 833
user3642768 Avatar asked Mar 12 '15 05:03

user3642768


2 Answers

Probably browser can not find your external js file, because of wrong path. Try to put function inside the <head> section of the page and if worked, The problem is wrong path to js file.

like image 169
hamed Avatar answered Sep 25 '22 17:09

hamed


You have to write following javascript code between <head> tag and make sure your given javascript file have valid path.

JavaScript

<script type="text/javascript">
  function submitFunction() {
      alert("example");
  }
</script>

Demo

like image 41
Sadikhasan Avatar answered Sep 22 '22 17:09

Sadikhasan