Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on 

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?
jQuery

Avatar of undefined
Last Comment
Bruce Gust
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

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!
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

Pawan weighed in and I want to honor his time...
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

Thanks, friend!
jQuery
jQuery

jQuery (Core) is a cross-browser JavaScript library that provides abstractions for common client-side tasks such as Document Object Model (DOM) traversal, DOM manipulation, event handling, animation and Ajax. jQuery also provides a platform to create plugins that extend jQuery's capabilities beyond those already provided by the library.

19K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo