Reputation: 155
I have googled a lot and there seems to be a lot of talk regarding jQuery and the problem I'm having, however I'm using purely JavaScript.
I am just having a problem with not being able to validate the input because it is undefined.
**If my HTML is needed I will post, but i think this can be solved without it.
function fnValidation()
{
var validator = /^[a-zA-Z]*$/; //regex
var input = document.getElementById("fn").innerHTML;
if (!(input.match(validator)))
{
alert("Please enter only alphabetical characters!");
}
printReceipt();
}
I dug this old code up from a pervious problem and decided to salvage the username validation but am now having the problem described above
Upvotes: 1
Views: 2396
Reputation: 55
.innerHTML will return the string inside that id tag example here: jsfiddle
<h1 id="fn">Hello World!</h1>
the id is 'fn' the innerHTML is Hello Wold!
Upvotes: 0
Reputation: 136144
Input element doesn't have innerHTML, because all it has its value inside value attribute on html & value property Inside DOM.
You should use
document.getElementById("fn").value
Upvotes: 1
Reputation: 418
should be var input = document.getElementById("fn").value and not innerHTML
Upvotes: 0