Run JavaScript function on form submit

Viewed 15984

Trying to get back into Javascript, having a little trouble with this very basic thing.

https://jsfiddle.net/gfitzpatrick2/aw27toyv/3/

var name = document.getElementById("name");
function validate() {
  alert("Your name is " +name);
}
<form action="" method="post" name="myForm">
  <label>Name</label>
  <input type="text" name="name" id="name" />
  <input type="submit" name="submit" onclick="validate()" />
</form>

Just wanted a pop up box showing the name you have entered in the field, not sure why it's not working. Am I way off?

Thanks.

1 Answers
Related