Javascript

I'm working with (not on) an ASP based auction system (XCAuction) and the client is asking me to do some customization.

Thier chosen template style has the navagation at the bottom of ever page (?????) but they would like it at the top as well. The problem, for me, arises because I cannot just include the ASP script that creates the the bottom menu in the top menu because the header template is strictly html.

Now, I could go into every single template page of the system and add the ASP before or after the header, but that would take weeks and be just ugly.

The good thing: The menu has only three choices; main menu, auction help, and login/logout. The ASP script just handles the login/logout decision by reading the cookie (or lack their of)

The bad thing: I know zero javascript! I would run out and buy a book (actually I already have one) but I don't have time. Any help would be great.

All I need to do is read the cookie and then have the html display the login or logout link depending on what it finds.

This is as far as I have gotten trying to use an example from a javascript site :eek:

<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function ReadCookie(cookieName) {
var theCookie=""+document.cookie;
var ind=theCookie.indexOf(cookieName);
if (ind==-1 || cookieName=="") return "";
var ind1=theCookie.indexOf(';',ind);
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
</script>
</head>

<body>



<A HREF="XUDLogout.asp">Logout</A>
<br>
<A HREF="XUDLogin.asp">Login</A>

I really have no idea what any of that means.

Can anybody give me a shove?

Thanks,

Brent
 
soundcompanies said:
Can anybody give me a shove?

Try this:

<body>

<script type="text/javascript">
<!--
if (ReadCookie("putyourcookienamehere") == "")
document.write('<A HREF="XUDLogin.asp">Login</A>');
else
document.write('<A HREF="XUDLogout.asp">Logout</A>');
// -->
</script>

No guarantee this will work, as it is untested and completely off the top of my head.

riley
 
Thanks for the nudge Riley.

The code seems to work partially, but I'm still not getting it to work fully. It shows login regardless of whether I'm logged in or logged out.

Here is the ASP code for the bottom navigation:
If Len(Request.Cookies("Xc")("LoginKey")) > 0 Then
Response.Write "&nbsp;&nbsp;|&nbsp; "
Response.Write "<A HREF=""" & gsXUDURL & "XUDLogout.asp"">" & GLS_NBT_Logout & "</A>"
Else
Response.Write "&nbsp;&nbsp;|&nbsp; "
Response.Write "<A HREF=""" & gsXUDURL & "XUDLogin.asp"">" & GLS_NBT_Login & "</A>"
End If

This is what the cookie looks like:
XcAuc
EscrowBMV=0&ShipViaBMV=0&ShipLimitBMV=0&PaymentBMV=0&OwnerStatEmail=True&RegionID=0&ShipCostBMV=0
localhost/eq**-**an.net
1024
3165810688
29695322
433514992
29621973
*

The name of the cookie: eq**-**an
The path of the cookie: cityb@localhost/eq**-**an.net

Any ideas?

Thanks again,

Brent
 
I once did it in ASP .net (with an .ascx control page, which had to appear on each and every page)

This is the code behind a logoff button :

Code:
   Private Sub BtnLogoff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLogoff.Click
    Dim Cookie As HttpCookie
    Cookie = Request.Cookies("ITNN_LoginData")
    Cookie.Expires = Now.AddDays(-1)
    Response.AppendCookie(Cookie)
    If Not Request.QueryString("ITl") Is Nothing And Not Request.QueryString("ITl") = "error404" Then
      Response.Redirect("../default.aspx?ITl=" & Request.QueryString("ITl"))
    Else
      Response.Redirect("../default.aspx")
    End If
  End Sub

This code actually makes the cookie if it does not exist.

Code:
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.TDHighlight.Controls.Add(LoadControl("../includes/index_highlight_sub.ascx"))
    If Not IsPostBack Then
      Dim Cookie As HttpCookie = Request.Cookies("ITNN_LoginData")
      If Not Request.Cookies("ITNN_LoginData") Is Nothing Then
        BtnLogoff.Visible = True
        cellMember.Controls.Add(LoadControl("../includes/index_topright_u_login.ascx"))
        Dim qS As New DataRetrievalOne
        qS.Retrieve("itnn", "SELECT * from I_User where [username] = '" & CStr(Cookie.Values("Username")) & "' and [password] = '" & CStr(Cookie.Values("UserPass")) & "'")
        While qS.ObjDR.Read()
          If qS.ObjDR("group") = 5 Then
            Dim tabAdm As New TableCell
            Dim tabStrp As New TableCell
            tabStrp.Text = " | "
            tabAdm.Text = "<a href='../admin/default.aspx'>admins</a>"
            navBar.Rows(0).Cells.Add(tabStrp)
            navBar.Rows(0).Cells.Add(tabAdm)
          End If
        End While
        qS.Close()
      Else
        BtnLogoff.Visible = False
        cellMember.Controls.Add(LoadControl("../includes/index_topright_u_register.ascx"))
        TD4.Controls.Clear()
        TD4.Controls.Add(LoadControl("../controls/index_prohibited.ascx"))
      End If
    End If
  End Sub

Regards,
Niels
 
I decided to just scrap the Javascript method alltogether.

The way the XCAuction ASP handles the header is that it reads the header htm file into a var as a text file. It finds where the header should end and the content should begin, it inserts the content, and then it reads in the footer. After all of that, it outputs the var to build the html for the whole page.

Since it does this for every single page, I just entered %loginlogout% in the header htm. Then when I read in the header, I replace that var with the current session state, either logged in or logged out and respective link. The other menu items are static so I don't have to worry about them.

This whole method of building the pages seems rediculous to me, but I'm not an ASP guy so maybe it's status quo. Either way, I accomplished my goal without using js, which is fine with me. I'm not one for client side scripting. The Javascript book will go back on the shelf for another day!

Thank you for your replies,

Brent
 
Back
Top