JavaScipt: edit text value in html textArea elements

1 09 2012

Here is how to edit text in a web page textArea component programatically by JavaScript function. Put it in page <head>:

<script language="javascript" type="text/javascript">
function addtext() {
	var newtext = "Text to display";
	document.myform.outputtext.value = newtext;

Then call this method after button click:

onclick="addtext() "

as this function is quite simple, it is more efficient to call it inline, without declaring it in <head>:

onclick="document.myform.outputtext.value = 'Text to display';"

If you need to append text to already existing text, just use += operator:

onclick="document.myform.outputtext.value += 'Text to display';"

Here you will find more detailed examples on issue described. Also please consider where do you put your JavaScript functions. Here are some advices on it. Follow them to mak your page load faster.

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!




Give Your feedback:

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: