0

Hello I have a function

Fortune.prototype.entername = function () {
    var person = prompt("Please enter your name", "Harry Potter");
    if (person != null) {
        document.getElementById("demo").innerHTML =
        "Hello " + person + "! Check Your Fortune";
    };
    this.words();
} 

I want to call it using button here is my code <p class="dark" id="demo"><button onclick="this.entername()">Click to Enter Name & see your Fortune</button></p>

However it says this.entername() is not a function. Silly mistake I dont know how to call it full js code is here https://jsfiddle.net/e9zywrnt/

8
  • What do you think this is in the scope of an event handler attribute? Commented Apr 9, 2018 at 19:15
  • @Bergi I get error this.entername is not a function. I dont really know because in this case I am using .prototype in function. Before I just used to enter function name Commented Apr 9, 2018 at 19:17
  • What do you mean by before? It is really unclear how you expect an event handler on a DOM element to access your Fortune instance. Commented Apr 9, 2018 at 19:23
  • @Bergi I just want the Fortune.prototype.entername fnction to run when button is clicked Commented Apr 9, 2018 at 19:27
  • Possible duplicate of JavaScript: bind an object's method to event handler Commented Apr 9, 2018 at 19:29

0

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.