Why am I being told that "indexOf" is not a function?

Here's my code:

function validateForm() {
	var dob = document.getElementById("usrDOB");
	var usrEEID = document.getElementById("usrEEID");
	var error = '';
	if(usrEEID.indexOf("S")==-1)
	{
		$('#usrEEID').css('border', 'solid 2px red').focus();
		error = "Make sure you include a capital \"S\" in the Employee ID field!";
	}
	if (!isValidDate(dob.value)) 
	{
		$('#usrDOB').css('border', 'solid 2px red').focus();
		error = "Date of Birth must be in the format XX/XX/XXXX\n\r";
	} 
	else 
	{
		$('#usrDOB').css('border', '');
	}
	
	if (error.length > 0) {
		alert(error);
		return false;
	}
	return true;
}

Open in new window


Everything works except...

if(usrEEID.indexOf("S")==-1)
      {
            $('#usrEEID').css('border', 'solid 2px red').focus();
            error = "Make sure you include a capital \"S\" in the Employee ID field!";
      }

I keep getting an error that says "usrEEID.indexOf is not a function." What am I doing wrong?
brucegustPHP DeveloperAsked:
Who is Participating?
 
Pawan KumarDatabase ExpertCommented:
Pls try with this..

if(usrEEID.indexOf("S")=-1)
0
 
brucegustPHP DeveloperAuthor Commented:
Hey, Pawan!

I just deleted this question not realizing you had responded. I'll give the points just as a way to say, "Thank you" for your time.

I was able to figure it out. What I was lacking was this: var usrEEID = document.getElementById("usrEEID").value...

The ".value" is what made all the difference.

Thanks for your help, though!
0
 
brucegustPHP DeveloperAuthor Commented:
Pawan weighed in and I want to honor his time...
0
 
brucegustPHP DeveloperAuthor Commented:
Thanks, friend!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.