I'm following the answer from add onclick function to a submit button
Here's my HTML:
Name: <input type="text" id="name">
<br>
<br>
<input type="submit" onclick="return process();" />
and JS:
var text = document.getElementById("name").value;
function process() {
alert(text);
return true;
}
When I click the form, it says: Uncaught ReferenceError: process is not defined
I have double checked everything, and the process()
function is already defined. I wonder why this doesn't work
Here's the DEMO
==================UPDATE================================
I tried it using SO's code snippet, and it worked. I guess there's something wrong with jsfiddle, somehow the javascript and HTML are not conected
function process() {
var text = document.getElementById("name").value;
alert(text);
return true;
}
Name: <input type="text" id="name">
<br>
<br>
<input type="submit" onclick="return process();" />