Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Getting Started / May 2006



Tip: Looking for answers? Try searching our database.

Cookie with JS

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
umuayo - 25 May 2006 19:42 GMT
My client has a custom dhtml menu drop down that they bought. The added a login
text that is linked to the login page. What I am trying to accomplish is when
user logs into the system, write a cookie to with the first name of the User
and then change the text on the custom dhtml from "Login" to "logout" to the
javascript of the custom dhtml see below.
This is not working. when I add the below, the whole js drpdown craps out and
does not work again.

<!--- FROM THE login.cfm ---->
<!--- SET COOKIE.FNAME WITH THE USER FIRSTNAME  --->
<cfcookie name="fname" value="#memberinfo.fname#">

<!--- THIS IS THE CUSTOM JS --->
<script language="JavaScript">
function cdd_menu353871()       
       
tmpCookie = document.cookie;
tmpCookie = tmpCookie.split(";")
fcookie = 0;
               for(i=0;i<tmpCookie.length;i++)
                {
                     var c = tmpCookie<i>;
                     if(c.indexOf("fname") != -1)
                        {
                            fcookie = 1;
                            }
         }
                  if(fcookie == 1)
    {
        this.item7 = "LOGIN"
       }
    else
    {   
     this.item7 = "LOGOUT"
    }
       
       
/* If User is Logged in show Logout form */
                   if(fcookie == 1)
                    {
                           this.url7 = "<a target=_blank
class=ftalternatingbarlinklarge
href="http://www.xtremeparts.net/members/main.cfm"
">http://www.xtremeparts.net/members/main.cfm"
</a>                    }
                         else
                              {   
                                 this.url7 = "<a target=_blank
class=ftalternatingbarlinklarge
href="http://www.xtremeparts.net/members/logout.cfm"
">http://www.xtremeparts.net/members/logout.cfm"
</a>                       }   
</script>   
amadeusmax - 27 May 2006 22:12 GMT
It sounds like your a <cfif> away from a solution.

Without going into a great deal, this depends on your experience with
intermixing
cf functions with javascript. IF there is a null value or emptyspace with a
non login first name,
then I would use <cfif> to write one of two versions of the javascript.

>My client has a custom dhtml menu drop down that they bought. The added a login
BKBK - 28 May 2006 17:22 GMT
<i><script language="JavaScript"></i>
The current specifications (HTML 4.01) require <script type="text/javascript">

<i>function cdd_menu()</i>
Misses a pair of curly brackets. Also, supply an event to trigger the
function. (Doesn't have to be body-onload)

<i>this.item7</i>
It is not clear what object "this" refers to

<i>tmpCookie = document.cookie;
tmpCookie = tmpCookie.split(";")</i>
Perhaps the most serious error. You apparently don't realize
tmpCookie.split(";") is an array. I would instead write

tmpCookie = document.cookie;
tmpCookieArray = tmpCookie.split(";")

and then proceed accordingly.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.