Determine clicked link

So which link did the user click on? You may want to know the answer to this question especially when you are working with dynamic links. When you display dynamic links on your web pages, you likely want to know which link the user has clicked on to direct the user to the appropriate destination page. In the scripting code below, we first generate some dynamic links, and then, our script determines determine which link the user clicks on.

Scripting code

<%
dim strClickedLink, arrLinkText
' display dynamic links
DisplayLinks ()
' Now determine which link the user clicked on
' Notice in this function, we are passing "ClickableLinkID"
strClickedLink = GetClikedLink ("ClickableLinkID")
' Display clicked link, if any.
if strClickedLink <> "" then
response.write "You clicked on: " & arrLinkText (strClickedLink)
end if

' This subroutine displays dynamic links.
sub DisplayLinks ()
dim strLinkText, sOut, intLinkID
intLinkID = 0
' An array to store text for our dydnamic links.
arrLinkText = Array ("link1", "link2", "link3", _
"link4","link5","link6", "link7")
sout = "<p>Click on a link below:</p>"
sout = sout & "<ul>"
' Iterate through the array and display/create dynamic links
' the output is stored inside an output variable called sout
for each strLinkText in arrLinkText
sout = sout & "<li><a href='?ClickableLinkID=" & intLinkID & "'>"
sout = sout & strLinkText & "</li>"
intLinkID = intLinkID + 1
next
sout = sout & "</ul>"
response.write sout
end sub

' This function returns the value of ClickableLinkID present in the URL
function GetClikedLink (strLinkVar)
GetClikedLink = request.querystring(strLinkVar)
end function
%>

Output of the above code

Click on a link below: