Results 1 to 2 of 2

Thread: Anchor Element question

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 1999
    Location
    Ohio
    Posts
    59
    How can I get the displayed value when using <a href?

    If they click on a link that is defined as this,
    "<a href=somewhere.asp>Click here</a>"
    I want to be able to store the "Click here" in a variable to use later.

    Thanks.

  2. #2
    Guest
    Here's one way to do it using a hidden form variable to store the value. (You could use a JavaScript var instead of the hidden form variable).

    Code:
    <html>
    <head>
    <title>Link Example</title>
    </head>
    <body background="/images/bground.gif" bgcolor="#ffffff" text="#000000" marginheight="0" topmargin="0">
    
    <FORM NAME="frmTest" METHOD="POST" ACTION="test.asp">
    
    <INPUT TYPE="hidden" NAME="strTest" VALUE="">
    
    <P><A NAME="ancTest" HREF="test.htm" onClick="frmTest.strTest.value = ancTest.innerText; return false;">Click Here!</A></P>
    
    <P><BUTTON onClick="alert(frmTest.strTest.value)">Test</BUTTON></P>
    
    </FORM>
    
    </body>
    </html>
    This works fine on IE 5.5. It might not work on NS - I'm not sure if NS supports the 'innerText' thing. This example is less elegant but would work too. A literal string is used here...so you'd have to code it to assign the proper value.

    Code:
    <html>
    <head>
    <title>Link Example</title>
    </head>
    <body background="/images/bground.gif" bgcolor="#ffffff" text="#000000" marginheight="0" topmargin="0">
    
    <FORM NAME="frmTest" METHOD="POST" ACTION="test.asp">
    
    <INPUT TYPE="hidden" NAME="strTest" VALUE="">
    
    <P><A NAME="ancTest" HREF="test.htm" onClick="frmTest.strTest.value = 'Click Here!'; return false;">Click Here!</A></P>
    
    <P><BUTTON onClick="alert(frmTest.strTest.value)">Test</BUTTON></P>
    
    </FORM>
    
    </body>
    </html>
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width