SenjuXo
SenjuXo

Reputation: 155

Javascript undefined innerHTML

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

Answers (3)

HazeTek LLC
HazeTek LLC

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

Pankaj Parkar
Pankaj Parkar

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

Life is good
Life is good

Reputation: 418

should be var input = document.getElementById("fn").value and not innerHTML

Upvotes: 0

Related Questions