Solved

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

Posted on 2014-12-09
12
835 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 32

Expert Comment

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

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

Open in new window

0
 
LVL 32

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
 
LVL 32

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 32

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

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

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 32

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 32

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This video teaches users how to migrate an existing Wordpress website to a new domain.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now