Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Hyperlink Value to Form Text Box

Status
Not open for further replies.

mutiger83

IS-IT--Management
Apr 18, 2005
29
US
I am trying to create a hyperlink such as

<a href="#">Click Here</a> and have the value that is displayed, in this case "Click Here", copy to a text box on a form.

I am doing this because I have a table with a list of mutliple ID's and I would like each to be a hyperlink and when the user click's on the ID (a hyperlink) it will copy the value of the hyperlink to a field on a form on the page.

Is this possible? It seems it should be....
 
You don't have to do this with a hyperlink, but I'll show you how as this can be done to any element that has the ability to have an onclick handler.

Add an onclick handler to call a function when the anchor is clicked and pass the anchor object.

Code:
<a [!]onclick="getAnchorText(this)"[/!] href="#">Click Here</a>

The function would grab the innerHTML of the anchor tag and put it in the textbox:

Code:
function getAnchorText(anchorObj) {
   var textBoxValue = anchorObj.innerHTML;
   document.forms["formName"].elements["textBoxName"].value = textBoxValue;
}

That should be all you need.





<.

 
Like this?
Code:
<a href="#" onclick="document.getElementById('theTextbox').value = this.innerHTML">Click Here</a>
<input type="text" id="theTextbox" />

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
[purple]You're welcome[/purple]

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top