Solved

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

Posted on 2014-12-09
12
967 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 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
"Go Fund Me" type plugin 5 40
Select case on click 3 26
Update the value of table B with value of table A tables inner join 6 75
Barracuda WAF Training? 2 26
Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

740 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