?
Solved

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

Posted on 2014-12-09
12
Medium Priority
?
1,068 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1500 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

777 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