JavaScipt: edit text value in html textArea elements

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;
}
</script>

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: