how to insert value of an textarea to another textarea with javascript - Stack Overflow

Well this is what i mean. Lets say i have 2 textarea:<textarea id="first" class="txta

Well this is what i mean. Lets say i have 2 textarea:

<textarea id="first" class="txtarea" name="in_first" cols="80" rows="15">First Textarea</textarea>

and:

<textarea id="second" class="txtarea" name="in_second" cols="80" rows="15">First Textarea</textarea>

In the final result, I want to move the value of the first textarea to the second textarea with javascript only, please do not sugest me any other programing language.

I already get the value of the first textarea with code like the following:

var textAreaValue = $("#first").text();

now, how can i insert it to the second textarea? or maybe you have another method, please let me know.

Well this is what i mean. Lets say i have 2 textarea:

<textarea id="first" class="txtarea" name="in_first" cols="80" rows="15">First Textarea</textarea>

and:

<textarea id="second" class="txtarea" name="in_second" cols="80" rows="15">First Textarea</textarea>

In the final result, I want to move the value of the first textarea to the second textarea with javascript only, please do not sugest me any other programing language.

I already get the value of the first textarea with code like the following:

var textAreaValue = $("#first").text();

now, how can i insert it to the second textarea? or maybe you have another method, please let me know.

Share Improve this question asked May 20, 2013 at 9:53 RK26RK26 3831 gold badge7 silver badges20 bronze badges 2
  • 1 Uhm, but you're using jQuery ? – adeneo Commented May 20, 2013 at 9:55
  • 1 We nay guess that under any other programming language you mean something like VBScript. If you mean jQuery, then jQuery is a JavaScript library. So what exactly do you mean by any other programming language? – VisioN Commented May 20, 2013 at 9:58
Add a ment  | 

6 Answers 6

Reset to default 6

Using jquery val() method:

$firsttextarea=$("#first").val();
$('#second').val($firsttextarea);

Using jquery text() method:

$firsttextarea=$("#first").text();
$('#second').text($firsttextarea);

Then, with JS only (no libraries):

var firstTextArea = document.getElementById('first');
document.getElementById('second').value = first.value;

//clearing the first
first.value = '';

In pure JavaScript it should look like:

var value = document.getElementById("first").value;
document.getElementById("second").value = value;

Pay attention that for form elements (like <textarea>) you should address value property.

If you want to clear the value of the first <textarea> then do:

document.getElementById("first").value = "";

With jQuery

$('.second').val($('.first').val());

This is just for your information.

html

<textarea id="first" class="txtarea" name="in_first" cols="80" rows="15">First Textarea</textarea>

<textarea id="second" class="txtarea" name="in_second" cols="80" rows="15">First Textarea</textarea>

jquery

var FristTextAreaValue = $("#first").val();
var SecondTextAreaValue = $("#second").val();

You could use jQuery:

var textAreaValue = $("#first").text();
$("#second").text(textAreaValue);

to clear textArea you could use:

$("#first").text("");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745601008a4635401.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信