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!

add link in textarea

Status
Not open for further replies.

mike10101

Vendor
May 6, 2005
13
GB
Hi,

I am using the following function to insert a link on selected text in a textarea

function formatTextLink (tag) {
var selectedText = document.selection.createRange().text;

if (selectedText != "") {
var newText = "<a href='" + tag + "'>" + selectedText + "</a>" ;
document.selection.createRange().text = newText;
}
}


onClick="formatTextLink('

This works great but ideally I would like to be able pre-specify the address in another textfield and then insert this address

any help would be greatly appreciated.
 
Let's say you have another text field with an id of "myUrl":

Code:
<input type="text" id="myUrl">

then you can use this to pick the URL from that field:

Code:
onclick="formatTextLink(document.getElementById('myUrl').value);"

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top