Imagine having an <input>
and a <textarea>
along with some JavaScript code that sends the value of the <input>
to the <textarea>
with additional text. How can you achieve this task?
The text-transform: capitalize
property is set in the style of the <input>
element. However, the text from the <input>
does not get transferred to the <textarea>
with proper capitalization. Applying text-transform: capitalize
to the <textarea>
makes all words capitalized, which is not desired. How can you work around this issue?
function sendText(){
var input =document.getElementById("input");
var textarea =document.getElementById("textarea");
textarea.value ="My name is " + input.value;
}
input{
margin-right:10px;
float:left;
text-transform: capitalize;
}
textarea{
height:30px;
width:140px;
float:left;
}
<html>
<body>
<input id="input" onkeyup="sendText()" placeholder="Your Name Here"><textarea id="textarea"></textarea>
</body>
</html>