Click to See Complete Forum and Search --> : Anchor Element question
JasonS
Jan 5th, 2001, 04:34 PM
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.
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).
<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.
<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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.