Solved

How to get an html anchor tag href value when clicking that href link

Posted on 2014-12-09
12
913 Views
Last Modified: 2014-12-16
I have a classic asp page with 5 anchor tags. When clicking any one of the tag, i want to get the value of that href tag (or  the DocType value) and want to store that in a session.

<%
var strSearchUrl = getFilePath( "CustomSearchdsp.asp")
%>
            <TABLE id = customize margin-left = 49px; margin-right:49px;>
            <TR>
                  <TD><A HREF  = "<%=strSearchUrl%>?DocType=Ordinance"> Ordinance </A></TD>
            </TR>
            <TR>
                  <TD><A HREF   = "<%=strSearchUrl%>?DocType=Resolution"> Resolution </A></TD>
            </TR>
            <TR>
                  <TD><A HREF  = "<%=strSearchUrl%>?DocType=Agenda"> Agenda </A></TD>
            </TR>
            <TR>
                  <TD><A HREF  = "<%=strSearchUrl%>?DocType=Minutes"> Minutes </A></TD>
            </TR>
            <TR>
                  <TD><A HREF  =  "<%=strSearchUrl%>?DocType=Permits"> Permits   </A></TD>
            </TR>
            </TABLE>
0
Comment
Question by:pothireddysunil
  • 7
  • 4
12 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 40489444
use Request.QueryString on CustomSearchdsp.asp:

Session("docType") = Request.QueryString("docType")

Open in new window

0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 40489449
if you want to get the FULL url (or the value of the href), you could do:

<% 
    prot = "http" 
    https = lcase(request.ServerVariables("HTTPS")) 
    if https <> "off" then prot = "https" 
    domainname = Request.ServerVariables("SERVER_NAME") 
    filename = Request.ServerVariables("SCRIPT_NAME") 
    querystring = Request.ServerVariables("QUERY_STRING") 
    Session("url") = prot & "://" & domainname & filename & "?" & querystring 
%>

Open in new window

0
 
LVL 1

Author Comment

by:pothireddysunil
ID: 40489512
Hi Monty, I tried both and they are not working. so, i am thinking of some script to get the clicked anchor href value and text value. Is there any way to do this.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 33

Expert Comment

by:Big Monty
ID: 40489516
I tried both and they are not working

this is pretty vague...WHAT'S not working? error? not the desired results?

maybe if you post your code, I can spot where you went wrong
0
 
LVL 1

Author Comment

by:pothireddysunil
ID: 40489542
This is my whole asp page and i am getting the value for Request.QueryString("DocType") as undefined

<%            
      expirePage();
      Response.Buffer=true;

      var uid = "DMUser";
      Session("user") = uid;
      var pwd = "password";
      var lib = "DOCSLIB_TEST";
      var alias = "";
      var IWAloginedUser = uid;
      var mustLogin = "N";
      var forceLogin = "N";
      Server.ScriptTimeout = 1200;

      var sysParms = new SystemParameters();
      var bis = sysParms.getBuiltInSymbols();


          bis.AllowAutoLogin  = 1;
      if(1 == bis.AllowAutoLogin)
      loginToLibrary( uid, pwd, lib, alias )

      setSearchLibraries();

      Session("Start") = "";

      if(Session("Start") == "")
      {
      strDocType = "" + Request.QueryString("DocType");

      Response.write(" this is a test " + strDocType);

       Response.write("sesson value 1" + Session("Start"));
           Session("Start") = 0;
      }
      else
      {
       Response.write("sesson value 2" + Session("Start"));
           Session("Start") = 0;
      }

      Session("noframes") = "YES";

      var strSearchUrl = getFilePath( "CustomSearchdsp.asp");
%>
<html>
<TABLE id = customize margin-left = 49px; margin-right:49px;>
      <TR>
            <TD><A HREF  = "<%=strSearchUrl%>?DocType=Ordinance"> Ordinance </A></TD>
      </TR>
      <TR>
            <TD><A HREF   = "<%=strSearchUrl%>?DocType=Resolution"> Resolution </A></TD>
      </TR>
      <TR>
            <TD><A HREF  = "<%=strSearchUrl%>?DocType=Agenda"> Agenda </A></TD>
      </TR>
      <TR>
            <TD><A HREF  = "<%=strSearchUrl%>?DocType=Minutes"> Minutes </A></TD>
      </TR>
      <TR>
            <TD><A HREF  =  "<%=strSearchUrl%>?DocType=Permits"> Permits   </A></TD>
      </TR>
</TABLE>
</html>
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40491559
upon initial page load, yes, it'll be undefined. it will only populate once you click one of the links.

and just to clarify, this IS classic asp, and not asp.net, correct?
0
 
LVL 1

Author Comment

by:pothireddysunil
ID: 40492462
Yes Monty. it's classic asp
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40492464
and when you click the link, it still comes up as undefined?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40492859
You are mixing ASP and Javascript/C# etc code - nothing to do with classic ASP

Things like this are the javascript/C# and other languages' way of writing code
      if(Session("Start") == "")
       {

    var strSearchUrl
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 40493985
@Gary: I saw that as well, and I'm assuming they are using server side javascript, they just don't have the tag on line 1 defining that.

@pothireddysunil: I tested the code out below and it works. I did have to un-comment some the javascript functions as I presume they're coming from an include file.

<%@language="javascript"%>

<%            
     // expirePage();
      Response.Buffer=true;

      var uid = "DMUser";
      Session("user") = uid;
      var pwd = "password";
      var lib = "DOCSLIB_TEST";
      var alias = "";
      var IWAloginedUser = uid;
      var mustLogin = "N";
      var forceLogin = "N";
      Server.ScriptTimeout = 1200;

      //var sysParms = new SystemParameters();
      //var bis = sysParms.getBuiltInSymbols();


      //    bis.AllowAutoLogin  = 1;
      //if(1 == bis.AllowAutoLogin)
      //loginToLibrary( uid, pwd, lib, alias )

      //setSearchLibraries();

      Session("Start") = "";

      if(Session("Start") == "")
      {
      strDocType = "" + Request.QueryString("DocType");

      Response.write(" this is a test " + strDocType);

       Response.write("<br/>sesson value 1" + Session("Start"));
           Session("Start") = 0;
      }
      else
      {
       Response.write("<br/>sesson value 2" + Session("Start"));
           Session("Start") = 0;
      }

      Session("noframes") = "YES";

      var strSearchUrl = ( "test.asp");
%>
<html>
<TABLE id = customize margin-left = 49px; margin-right:49px;>
      <TR>
            <TD><A HREF  = "<%=strSearchUrl%>?DocType=Ordinance"> Ordinance </A></TD>
      </TR>
      <TR>
            <TD><A HREF   = "<%=strSearchUrl%>?DocType=Resolution"> Resolution </A></TD>
      </TR>
      <TR>
            <TD><A HREF  = "<%=strSearchUrl%>?DocType=Agenda"> Agenda </A></TD>
      </TR>
      <TR>
            <TD><A HREF  = "<%=strSearchUrl%>?DocType=Minutes"> Minutes </A></TD>
      </TR>
      <TR>
            <TD><A HREF  =  "<%=strSearchUrl%>?DocType=Permits"> Permits   </A></TD>
      </TR>
</TABLE>
</html>

Open in new window


working example
0
 
LVL 1

Author Closing Comment

by:pothireddysunil
ID: 40502857
thanks
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40502901
just curious, why the grade of B? what more were you looking for in an answer?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question