#1
  1. No one Important
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Australia
    Posts
    524
    Rep Power
    15

    Simple Javascript if() check.......


    Hey there, I need to be able to read in a cookie set under php, but check the value, and if the value is set to a 0 does nothing.... what I have is:-

    Code:
    <script>
    var varID = readCookie('ThemeID');
    
    if (varID==1)
    {
    
    	document.write("<style type="text/css">");
    	document.write("<!--");
    	document.write("#contentDiv");
    	document.write("{");
    	document.write("background:#fff url(/images/TEMP_pests_overview_img.jpg) no-repeat;");
    	document.write("}");
    	document.write("#aboutCol");
    	document.write("{");
    	document.write("/*padding-top could be set 0 here if no bg img in #contentDiv*/");
    	document.write("}");
    	document.write("-->");
    	document.write("</style>");
    }
    </script>
    Is the above syntax correct? basically I need it to write to the file the the style code if the cookie is switched on.

    Any help would be great.......
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    24
    You should just need to check the cookie is present, because it should have been deleted/not present in it's 'switched off' state. You can do this by:

    if (document.cookie.indexOf("ThemeID") != -1) {

IMN logo majestic logo threadwatch logo seochat tools logo