Pi Horse
Pi Horse

Reputation: 2440

Link a textarea to something

I have a textarea in inside which the user adds some content and edits it time to time.

I want to have that text point to URL (i.e a hyperlink inside a textarea). But since itis not possible to have a hyperlink inside a textarea, is it possible to make the whole textarea link to a URL itself ?

Upvotes: 0

Views: 129

Answers (2)

DiverseAndRemote.com
DiverseAndRemote.com

Reputation: 19888

you can use jquery:

<a href='http://example.com' style='display:none' id='textarea_link'></a>
<textarea id='textarea1'></textarea>

<script type='text/javascript'>
    jQuery('#textarea1').click(function(){jQuery('#textarea_link').click()});
</script>

Then when you click on the textarea it will pass the click event onto a link and your browser will treat it as if you clicked on the link.

Note: this is not using the javascript window.open function on purpose

Upvotes: 1

epascarello
epascarello

Reputation: 207537

Add onclick event handler to the textarea and set window.location with the location you want to do to.

Other option is to use a editor like CK Editor or YUI Editor

Upvotes: 2

Related Questions