By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

How to delete a session with Javascript

P: 12
hiya, i got some code where i set a session. however, i cant seem to delete it in the normal way, by setting a value and posting back, then if value is true, deleting session.

So im wondering if theres a way of deleting the session via java script at all?

this is my code if anyones interested.





Expand|Select|Wrap|Line Numbers
  1. <DIV id=Rightbody>    
  2.  
  3.     <SCRIPT LANGUAGE="JavaScript">
  4.         <!--
  5.             function LoginWithForm(Bang)
  6.             {
  7.                 //Variables will be retrieved from submitted form
  8.                 //alert ('Bang');
  9.                 //document.Rightbody.txtLogOut.value = "boo";
  10.                 document.Rightbody.submit();
  11.                 return true;
  12.             }
  13.  
  14.  
  15.             function LogOutWithForm(bang)
  16.             {
  17.                 //Variables will be retrieved from submitted form
  18.                 document.login.txtLogOut.value = "BOO";
  19.                 document.RightBody.submit();
  20.                 return true;
  21.             }
  22.         -->
  23.     </SCRIPT>
  24.  
  25. <FORM id="RightBody" name="Rightbody" method="post">
Expand|Select|Wrap|Line Numbers
  1.     <% 
  2.     'VB Scipt in here (server side)
  3.     dim Username
  4.     dim Password
  5.     dim strXMLLoginDetails
  6.     dim strlogout
  7.  
  8.     strlogout = Request.Form("txtLogOut")
  9.     Response.Write strlogout    
  10.  
  11.     Username = Request.Form("txtUser")
  12.     Password = Request.Form("txtPassword")    
  13.     strXMLLoginDetails = "<HXML><Username>" & Username & "</Username><Password>" & Password & "</Password></HXML>"
  14.     %>
Expand|Select|Wrap|Line Numbers
  1.             <Table>
  2.                 <tr>
  3.                     <td><input type="text" id="txtLogOut" name="txtLogOut"></td>
  4.                 </tr>
  5.             </Table>
  6.  
Expand|Select|Wrap|Line Numbers
  1.  
  2.     <%
  3.     If Username <> "" OR Password <> "" then
  4.  
  5.         dim objLoginNode
  6.         set objLoginDLL = createobject("Logindll.LoginClass")
  7.  
  8.         dim GetLoginResult
  9.         GetLoginResult = objLoginDLL.LoginEntry(strXMLLoginDetails)
  10.  
  11.         set objDOM = server.CreateObject("MSXML2.DOMDocument")
  12.         objDOM.LoadXML(GetLoginResult)
  13.  
  14.         if objDOM.selectSingleNode("Response/RESULT").Text ="SUCCESS" then
  15.  
  16.                 Session("Loggedin")=objDOM.selectSingleNode("Response/LOGIN/MembersName").Text
  17.                 Response.Write "You are logged in:"%><P><H3><% Response.Write Session("Loggedin")%></H3><BR>
  18.  
  19.  
  20.             <input type="submit" value="log-out" id=log-out name=log-out onClick="LoginWithForm();">    
  21.         <%
  22.         else
  23.                 Response.Write "The details you entered are incorrect"
  24.         end if
  25.  
  26.     else
  27.  
  28.         if Session("Loggedin") <> "" then 
  29.  
  30.             Response.Write "You are logged in:"%><P><H3><% Response.Write Session("Loggedin")%></H3><BR>
  31.  
  32.  
  33.  
  34.             <input type="submit" value="log-out" id=log-out name=log-out onClick="LoginWithForm();">    
  35.         <%
  36.         else
  37.         %>
  38.  
Expand|Select|Wrap|Line Numbers
  1.             <Strong>
  2.                 <BR />
  3.                     <label>Username</label>
  4.                 <BR />
  5.                     <input type="text" id=txtUser name=txtUser maxlength="12">
  6.                 <BR />
  7.                 <BR />
  8.                     <label>Password</label>
  9.                 <BR />
  10.                     <input type="password" id=txtPassword name=txtPassword maxlength="12">
  11.                 <BR />
  12.                 <BR />
  13.                     <input type="submit" value="log-in" id=log-in name=log-in onClick="LoginWithForm();">    
  14.                     <input type="reset" value="Reset" id=reset1 name=reset1>
  15.             </Strong>
  16.  
  17.                 <BR>
  18.         <%
  19.         End if
  20.     end if
  21.     %>
  22.  
  23. </FORM>
  24.  
  25. </DIV>
Jan 17 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
You can't delete a session with JavaScript. Sessions can be deleted server-side, in your case with ASP.
Jan 18 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.