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 byany other programming language
? – VisioN Commented May 20, 2013 at 9:58
6 Answers
Reset to default 6Using 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条)