Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form which contains four textboxes and one textarea field. the form something like request form. I want the content of four textboxes get copied to textarea. For this i have write onkeyup event which simultaneously copy its value to textarea but i want all the four textbox values get copied to the text area. This is the code i write for onkeyup event

HTML
<input type="text"  id="C.name" name="C.name" required   önkeyup="document.getElementById('message').value=this.value">


But with this event only one textbox value get copied. I want all the textbox value get copied to textarea.
What should i do so that the value of all textbox get copied to textarea?
Posted

1 solution

I have 3 text boxes here. and 3rd one is updating by other two text boxes. Like wise you can intergrate it to your requirement

HTML

HTML
Fisrt name:-<input type="text" id="first" ></input>
Last Name:-<input type="text" id="last" onkeyUp="copyText()" ></input>
Full Name:-<input type="text" id="full" ></input>


JS
JavaScript
function copyText() {
first = document.getElementById("first");
last = document.getElementById("last");
full = document.getElementById("full");
full.value = first.value + ' ' + last.value;
}
 
Share this answer
 
Comments
Member 10276989 3-Sep-14 7:31am    
Is there also an onkeyup event for textarea? @Gihan Liyange
Rocker-Star 3-Sep-14 7:32am    
Yes you have
Gihan Liyanage 3-Sep-14 7:33am    
Yes, its working for me, Here is the full code I have written in simple html file. I tested it for you.

<!DOCTYPE html>
<html>
<head>
<script>
function copyText() {
first = document.getElementById("first");
last = document.getElementById("last");
full = document.getElementById("full");
full.value = first.value + ' ' + last.value;
}
</script>
</head>
<body>

Fisrt name:-<input type="text" id="first" ></input>
Last Name:-<input type="text" id="last" önkeyUp="copyText()" ></input>
Full Name:-<input type="text" id="full" ></input>

</body>
</html>
Gihan Liyanage 3-Sep-14 7:36am    
I used this w3schools js Editer,

http://www.w3schools.com/JS/tryit.asp?filename=tryjs_onchange

Paste this code and click on submit button. You can see the result
Member 10276989 3-Sep-14 7:39am    
But this onkeyup not working for text area

<textarea class="required" id="message" name="message" placeholder="Your message" önkeyUp="copyText()" ></textarea>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900