/    Sign up×
Community /Pin to ProfileBookmark

Links that change text in textarea.

Hi there, I hope I find my javascript guru here…

I want to change the text of a textarea by clicking on a link. So when you click on “Link 1”, it shows something like “This is link 1”, and if you click on “Link 2” you get “This is link 2” etc.

It is important that the previous text is cleared before displaying the new text.

Can it be done??

I was gonna hide layers with textareas in each one then use the links to show them, but that’s alot of coding.

Any help is greatly appreciated.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterJul 11.2005 — Something like this?
<i>
</i>&lt;script type="text/javascript"&gt;
function changeStatus(){
document.getElementById("linkStatus").value=arguments[0]
}
&lt;/script&gt;
&lt;textarea id="linkStatus"&gt;&lt;/textarea&gt;&lt;br&gt;
&lt;a href="#" onclick="changeStatus('this is link 1')"&gt;link1&lt;/a&gt;&lt;br&gt;
&lt;a href="#" onclick="changeStatus('this is link 2')"&gt;link2&lt;/a&gt;&lt;br&gt;
&lt;a href="#" onclick="changeStatus('this is link 3')"&gt;link3&lt;/a&gt;&lt;br&gt;
Copy linkTweet thisAlerts:
@W8_4meauthorJul 11.2005 — Is there any way to use speech marks and apostrophies in the textarea without disrupting the code?
Copy linkTweet thisAlerts:
@Tweak4Jul 11.2005 — Either use a slash in front of the character
<a href="#" onclick="changeStatus('this is 'link 1'')">link1</a>[/QUOTE]

Or use escape characters
<a href="#" onclick="changeStatus(unescape('this is %22link 1%22'))">link1</a>[/QUOTE]
Copy linkTweet thisAlerts:
@W8_4meauthorJul 11.2005 — Dooom! It works, don't get me wrong. Here's what I'm trying to do with one textarea:

  • 1. I have a script which prompts for the visitors first name. That name gets added into the textarea.

  • 2. I have a script which allows you to click on a button to copy the textarea's contents onto the clipboard.

  • 3. The last script is the one I asked for here, so I can change the contents of the textarea using a link.


  • The first script requires me to declare the textarea like this:

    <i>
    </i>&lt;script language="javascript"&gt;
    &lt;!--hide
    document.write("&lt;textarea name='text2copy' id='linkStatus'&gt;Hello, " + yourname + ", you are a fool!&lt;/textarea&gt;");
    //--&gt;
    &lt;/script&gt;


    So, scripts 2 and 3 work fine, but script 1 doesn't. The " + yourname + " bit shows up as exactly that, it cannot be used to implement script 1.

    Can I have my cake and eat it?!
    Copy linkTweet thisAlerts:
    @W8_4meauthorJul 13.2005 — I guess that's a "no" then!
    ×

    Success!

    Help @W8_4me spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...