/    Sign up×
Community /Pin to ProfileBookmark

how do i add text to text area on click

Hi

I’m very new to javascript and stuck on something that might be fairly elementary!
What i want to do is add predefined text to a text area on click of an button (add). I also want to be able to remove it on clicking on another button (delete) I understand roughly what I’m doing here but the DOM has me stuck. Please can anyone help a frustrated newbie?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangJun 24.2006 — <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>add/remove text</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
function check(form) {
var txt="some text";
var obj=form.textarea1;
if(obj.value.search(txt)==-1) {
obj.value+=txt;
}
else {
obj.value=obj.value.replace(txt,'');
}
}
</script>

</head>
<body>
<form action="#" name="form1">
<fieldset><legend>form</legend>
<textarea rows="10" cols="20" name="textarea1">

<i> </i>&lt;/textarea&gt;
<i> </i>&lt;button type="button" onclick="check(this.form);"&gt;add/delete&lt;/button&gt;
&lt;/fieldset&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@musomanauthorJun 24.2006 — Thats great - that certainly gives me what i need. much appreciated
×

Success!

Help @musoman 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...