homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Just a simple JS script
What am I doing wrong???

 4:28 pm on Jan 23, 2002 (gmt 0)

Here is the code

<script type="text/javascript">
var cookieVar = "OneTwo"

If (cookieVar == "OneTwo")
document.write ("Great!")
elseif (cookVar != "OneTwo")
document.write ("Not so Great")

But I keep getting errors, specifically the "Object Expected".

Thanks for any help offered,
I appreciate it. :)



 4:57 pm on Jan 23, 2002 (gmt 0)

Found silly me forgot to put ;

at this line
var cookieVar ="OneTwo";


 9:38 pm on Jan 23, 2002 (gmt 0)

You also put "cookVar" instead of "cookieVar" in your else if clause.

that would cause an object error.


 9:08 am on Jan 24, 2002 (gmt 0)

Javascript is very case sensitive - it should be if not If. You also use elseif; this is invalid JS syntax and should be replaced with else if.

It should work then.

Also, as your if/else if is mutually exclusive you can just write:

if (cookieVar == "OneTwo")
document.write ("Great!")
document.write ("Not so Great")


 3:07 pm on Jan 24, 2002 (gmt 0)

thanks everyone. JS is not hard to learn but a pain. I'm used to coding with PHP. Which is a good server-side lang to learn by the way! (;)wink ;)wink) But getting into JS it's like starting all over again. I just keep pulling my hair till I eventually get it right.

OK I did'nt have to rant a rave so much. But sometimes you got to let it off your chest, you know? :)


 3:49 pm on Jan 24, 2002 (gmt 0)

Also the braces are optional. The if and else take one line. That line can be made compound by using the braces. But if you have only one line, the braces are optional. That makes it:

if (cookieVar == "OneTwo")
document.write ("Great!")
document.write ("Not so Great")

(wmw removes spaces at the start of the line, but you'd want to indent for readability)


 4:02 pm on Jan 24, 2002 (gmt 0)

This is neat. I'm learning JS from you guys and I understand you all better then some of this darn books I'm reading on it.

Who would have thought JS could be this much FUN!!!
Golly Gosh Gosh


 4:07 pm on Jan 24, 2002 (gmt 0)

I'm sorry should have put this in my last post.

What book would you guys recommend on JS and why?

I'm not looking for something to simple, cause that usually leaves me thinking too much. Something with too much info is just crazy. I always learn with time. A book that is somewhat in between that would be ideal, just enough info to where I know whats going on, but not so little information that I am left thinking thinking too much about it.



 4:32 pm on Jan 24, 2002 (gmt 0)

I'd recommend leaving in the optional { and }, for readability. It's just to easy to make mistakes by leaving them out.

I'm not really sure who thought this rule would be a good idea, but it's a common rule among a lot of langauges (even strongly typed langauges where they make the least sense).


 5:20 pm on Jan 24, 2002 (gmt 0)

I'd recommend the O'Reilly book. The new edition just came out in November and that makes it complete for the most recent standards.

This book is a reference, and not really a tutorial. I think the best way to learn js is to have some cut and paste scripts (the web is full of them - don't miss our generic javascript [webmasterworld.com] thread.) Then use an authoritative reference like O'Reilly to pull the code apart until it clicks for you.

<added>I just checked and the new 4th edition is on back order right now.</added>


 6:12 pm on Jan 24, 2002 (gmt 0)

I use both the O'Reilly Book - Javascript the Definitive Guide and the Javascript fr Professionals by WROX publishing.

Neither book has all the answers I need, so I usually flip between the two.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved