[Javascript] "Object Expected" Error

Rodney Myers rodney at aflyingstart.net
Fri May 3 03:06:47 CDT 2002


Try
if (string.indexOf("<TEXTAREA")>-1)

Your current expression
string.indexOf("<TEXTAREA")
gives the value -1 because there is no "<TEXTAREA"
-1 is TRUE not FALSE!
Only 0 is false.

hth

Rodney


SoitPP at aol.com wrote:

> Dear JavaScript list,
> I am getting an "Object Expected" Error when trying to
> call a certain function in a program. I don't quite understand
> what is causing this error. The program flow seems simple enough.
> What am I missing?
> Here is a duplication of the error in a cut down version:
>
> <html>
> <head>
> <title>Function Testing</title>
> <script language="JavaScript">
> function removeValue(string) {
> if (string.indexOf("<TEXTAREA")) {
> //line 17 follows
> string = string.substring(0,indexOf("<TEXTAREA")) +
> string.substring(indexOf("</TEXTAREA>",string.length))
> return string
> }
> return string
> }
> function robot() {
> preSTRvariable = document.body.innerHTML
> preSTRvariable = removeValue(preSTRvariable)
> }
> </script>
> </head>
> <body>
> <form>
> <button style="background-color: #FFFFFF" onClick="robot
> ()">Click</button>
> </form>
> </body>
> </html>
>
> Very simple right? So how come I get "Objected Expected" at line 17?
> Patiently,
> Aaron
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list