Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Expected error

Status
Not open for further replies.

allyeric

Programmer
Mar 14, 2000
104
CA
New to JavaScript here - I copied some script from a site, and there is an error in it.&nbsp;&nbsp;Can someone please let me know what is wrong with this code?&nbsp;&nbsp;First error:&nbsp;&nbsp;Expected &quot;(&quot;&nbsp;&nbsp;This occurs at the bolded line.&nbsp;&nbsp;Second Error:&nbsp;&nbsp;object expected&nbsp;&nbsp;&nbsp;This occurs at the red line, after I click the button.&nbsp;&nbsp;I do apologize for the newbie question, but have checked various sources on the net and haven't found any help. (If you can recommend any really good ones, it would be appreciated)<br>&nbsp;&nbsp;<br>Thanks for any help <br><br><br>&lt;SCRIPT&gt;<br>&lt;!--<br><b>var c=15</b><br>document.go.timer.value=&quot;15&quot;<br>function count()<br>{<br> if c = 0 <br> alert(&quot;Time is up&quot;)<br> window.location=&quot;saveanswers.asp&quot;<br> end if<br><br> document.go.timer.value=c<br><br> c=c-1<br> <br> setTimeout(&quot;count()&quot;,1000)<br>}<br><font color=red>//--&gt;</font><br>&lt;/SCRIPT&gt;<br> <br>&lt;form name=&quot;go&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;timer&quot; size=&quot;12&quot;&gt;&lt;input type=&quot;button&quot; value=&quot;Start&quot; <br>onClick=&quot;count()&quot;&gt;<br>&lt;/form&gt;<br>
 
It appears you need to learn a little more about syntax.&nbsp;&nbsp;You need to end each line with a semicolon and you need to use parenthesis around your if...then condition.&nbsp;&nbsp;The end_if is not a javascript statement. You also need to put the if..then statements to be executed within curly brackets {...}. Try modifying as such.<br><br>&lt;SCRIPT&gt;<br>&lt;!--<br>var c=15;<br>document.go.timer.value=15;<br>function count()<br>{<br>if (c = 0) <br>&nbsp;&nbsp;&nbsp;{alert(&quot;Time is up&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;window.location=&quot;saveanswers.asp&quot;;<br>&nbsp;&nbsp;&nbsp;}<br><br>document.go.timer.value=c;<br><br>c=c-1;<br><br>setTimeout(&quot;count()&quot;,1000);<br>}<br><br>//--&gt;&lt;/SCRIPT&gt;<br><br>&lt;form name=&quot;go&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;timer&quot; size=&quot;12&quot;&gt;&lt;input type=&quot;button&quot; value=&quot;Start&quot; <br>onClick=&quot;count()&quot;&gt;<br>&lt;/form&gt;<br><br><br>This SHOULD work unless I missed something trivial.<br><br>Russ
 
thanks Russ - I changed as you suggested, but am still getting errors<br><br>On the line that is bolded - I get &quot;Invalid Character&quot;<br>And, where it starts &lt;form name=&quot;go&quot;&gt;&nbsp;&nbsp;when I click, gives me error&nbsp;&nbsp;&quot;Object expected&quot;<br><br>This is how I have it on my page:<br><br>&lt;SCRIPT&gt;<br>&lt;!--<br>var c=15;<br>document.go.timer.value=15;<br>function count()<br>{<br><b>if (c = 0) </b><br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;alert(&quot;Time is up&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;window.location=&quot;saveanswers.asp&quot;;<br>&nbsp;&nbsp;&nbsp;}<br>document.go.timer.value=c;<br>c=c-1;<br>setTimeout(&quot;count()&quot;,1000);<br>}<br>//--&gt;<br>&lt;/SCRIPT&gt;<br><br>&lt;form name=&quot;go&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;timer&quot; size=&quot;12&quot;&gt;&lt;input type=&quot;button&quot; value=&quot;Start&quot; <br>onClick=&quot;count()&quot;&gt;<br>&lt;/form&gt;<br>
 
your script is using the wrong operator to test equality.<br>= is an assignment operator<br><br>if (c = 0)<br><br>should be<br><br>if (c == 0) <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
thanks Nick - I changed that.&nbsp;&nbsp;But, I still get errors.&nbsp;&nbsp;Line 209 Invalid Character, Line 220 Object Expected ..&nbsp;&nbsp;but I only have 200 lines on the page&nbsp;&nbsp;&nbsp;????
 
do you include files in your page ?? this would explain the number of lines ;)
 
no, I didn't include files - starting to feel like I am in the twilight zone here!  Maybe there is someone who might like to check my whole html page?  Perhaps there is something in there that I just can't see.  If anyone is interested, you can email me at <A HREF="mailto:allyeric@sympatico.ca">allyeric@sympatico.ca</A>, or post your email here and I will send it to you.<br><br>Thanks
 
I'll take a look.&nbsp;&nbsp;<A HREF="mailto:nick@bulka.com">nick@bulka.com</A> <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top