"indexof is not a function" and other oddities...

Discussion in 'JavaScript' started by PHP_Tyro, Feb 13, 2008.

  1. #1
    Hi folks.

    I'm trying to learn JavaScript and apply it practically at the same time, but running into a problem which I can't find a useful reference for.

    I'm sure you experts will see what I am trying to do here without a lot of explanation...

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Debugging JavaScript</title>
    
    <script language="JavaScript" type="text/javascript">
    
    function BanEmail(emailaddress)	{
    	var n;
    	var forbidden;
    	var searchresult;
    	
    	forbidden = new Array("yahoo.","hotmail.","msn.");
    			
    	for (n in forbidden)
    		{
    		searchresult = emailaddress.indexof(forbidden[n]);
    			
    			if(searchresult != -1)
    				{
    				alert("Found address containing: " + forbidden[n]);
    				break;
    				}
    		}
    }
    
    </script>
    </head>
    
    <body>
    
    <form>
    <input type="button" name="button" value="Click me!" onclick="BanEmail('xyz@Yahoo.com')">
    </form>
    
    </body>
    </html>
    
    Code (markup):
    The button is just there to send a Yahoo! address to the function - it'll be quite different once I get the function working properly.

    Maybe I'm completely off the track, but the problem that I know about that I can't overcome is the error message "emailaddress.indexof is not a function".

    A search for the string "indexof is not a function" turns up plenty of results but nothing that I can see helps me.

    Any help and suggestions most welcome.

    TIA
     
    PHP_Tyro, Feb 13, 2008 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    It means exactly what it says: String.indexof is not a function, whereas String.indexOf is a function.
     
    Logic Ali, Feb 14, 2008 IP
  3. The Critic

    The Critic Peon

    Messages:
    392
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Javascript is case-sensitive, so you have to keep on eye on things like that. The getElementById() method kept tripping me up for the longest time. If you see a message like that the first thing you should check is spelling, then case.
     
    The Critic, Feb 14, 2008 IP
  4. PHP_Tyro

    PHP_Tyro Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks guys -- live and learn!

    I'm most familiar with ASP and thus not used to case sensitivity in the language. Gotta learn that to watch that.

    Fixed the case thing and the other mistakes and all is working fine now.
     
    PHP_Tyro, Feb 14, 2008 IP