/    Sign up×
Community /Pin to ProfileBookmark

onclick function overwrites instead of copy

Hi all,

I have small issue with the below javascript code. I am trying to create a button which copies the text of one field into another text area. This works fine at the moment but now I want to copy the text into the textarea instead of overwrite the value which was entered previously. Any idea how to do this?

<html>
<body>

Field1: <input type=”text” id=”field1″ value=”Hello World!” />
<br />
<textarea name=”suggestions” rows=”5″ cols=”25″ id=”field2″></textarea>
<br /><br />
Click the button to copy the content of Field1 to Field2.
<br />
<button onclick=”document.getElementById(‘field2’).value=document.getElementById(‘field1’).value”>Copy Text</button>

</body>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Aug 15.2011 — += instead of =.
Copy linkTweet thisAlerts:
@NutBusterauthorAug 16.2011 — Perfect that works now. Is there a way that it remembers the mouse cursor and put the text behind the mouse cursor?
×

Success!

Help @NutBuster 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.29,
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,
)...