0

i am trying to make a simple hello message in html and javascript, but when the user enters their name, a hellomessage function is suppose to happen but nothing happens.

function ShowHelloMessage() {
  var name = document.getElementById("myname");
  document.getElementById("hellomessage").innerHTML = "Hello, " + name.value;
}
<form method="GET">
  What is your name: <input type="text" size="20" id="myname" onkeydown="if (event.keyCode == 13)  document.getElementById('mybutton').click()" />
  <input type="text" style="display: none;" />
  <button type="button" onclick="return ShowHelloMessage()" id="mybutton" class="button">Submit</button>
</form>
<div id="hellomessage"></div>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="javascriptHP.js"></script>
Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63
  • 1
    While I closed this as a duplicate, I went back and looked again and noticed you have `type="button"` so the button wasn't submitting the form. Then I tested your code and **could not reproduce the problem**. – Quentin Mar 21 '19 at 14:17
  • 1
    @Quentin reopen the question then? Can you? I made a snippet out of OP's original code, and it seems to work – Jeremy Thille Mar 21 '19 at 14:34
  • 1
    @JeremyThille — While I admit I closed the question for the wrong reason; since the code doesn't demonstrate the problem, it should still be closed. I'm not going to vote for it to be reopened just so it can be closed for a different reason. – Quentin Mar 21 '19 at 14:36

0 Answers0