HighDots Forums  

if cookie = ""

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss if cookie = "" in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
screechyboy@googlemail.com
 
Posts: n/a

Default if cookie = "" - 09-26-2007 , 03:25 PM






OKay so im new to Javascript Cookies....

I am able to set and return cookie values but i know want to create
an
if statement!


One of my cookies is called "color" and i wish to write a script that
displays a certain graphic if "Color" equals "White" for example.


The code i have so far is...
<script type="text/javascript">
color=getCookie('color')
if (color="White")
{
alert('Color = '+color+'!')


}


</script>

The alert appears when the page loads but ignores the IF statement so
just displays the value of "color" regardless of wether its value is
"White".


Im stuck and google searching is getting me knowhere, can this be
done?


Your help is greaty appreciated!


Reply With Quote
  #2  
Old   
Kirk Zurell
 
Posts: n/a

Default Re: if cookie = "" - 09-27-2007 , 04:06 PM






screechyboy (AT) googlemail (DOT) com wrote:

Quote:
if (color="White")
This is an assignment, not a test. Use '==' to test 'color'.

It is a valid expression, though. Some people write code like this:

if ( "White" == color ) ...

If you forget the second equals sign, the assignment fails. Not my
preference.

Kirk

--
Kirk Zurell
Byte Craft Limited
Waterloo, Ontario, Canada
http://www.bytecraft.com


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.