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
It means exactly what it says: String.indexof is not a function, whereas String.indexOf is a function.
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.
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.