0

Hey guys just having an issue with my HTML button not actually running my javascript function when clicked on.

The HTML:

<html>
<head>
<meta charset="utf-8">
<title>PROJECT</title>
<script language="javascript" src="Hangman.js"></script> 
</head>
<body>
  <input id = "Begin" type = "button" value = "Play">       
</body>
</html>

And here's the JS:

function start () 
    {
     document.getElementById("Begin").addEventListener("click",logic,false);
    }

function logic () 
    {
        document.writeln("yo");
    }

 window.addEventListener("load", start, false);

Sorry if this is an amateur question, it just so happens I'm an amateur. Thanks you guys in advance!

3
  • I just made two files: index.htm (with your HTML) and Hangman.js (with your JS). Your code works for me. Do you have Javascript turned on and is your file named Hangman.js in the same directory as your HTML file? Commented Aug 17, 2016 at 10:29
  • add alert("HI"); in first line of your js code to make sure it's loaded :-) Commented Aug 17, 2016 at 10:40
  • you could use document.addEventListener("DOMContentLoaded", start()) Commented Aug 17, 2016 at 12:30

1 Answer 1

1

check this jsfiddle it is fixed

function start () 
    {
     document.getElementById("Begin").addEventListener("click",logic,false);
    }

function logic () 
    {
       alert();
    }

window.onLoad=start();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.