admin管理员组文章数量:1429428
I am having a text area and a button.Like this :
<textarea id="txtarea"></textarea>
<input type="button" value="add text" id="add" />
Now,what i want to do is that on click of the button that text to be displayed on the same page above this text area just like we do ment or answer a question on stackoverflow.
How this can be done ?Please help.
I am having a text area and a button.Like this :
<textarea id="txtarea"></textarea>
<input type="button" value="add text" id="add" />
Now,what i want to do is that on click of the button that text to be displayed on the same page above this text area just like we do ment or answer a question on stackoverflow.
How this can be done ?Please help.
Share Improve this question asked Apr 27, 2014 at 11:23 user3522121user3522121 2153 gold badges10 silver badges24 bronze badges 4- 1 Please try something before asking other dude to code it for you. Why don't you read some basic tutos?! – A. Wolff Commented Apr 27, 2014 at 11:25
- yea dude atleast do the click handler here – Wilmer Commented Apr 27, 2014 at 11:27
- @A.Wolff I had basic knowledge but here in this case i dont know were to get started. – user3522121 Commented Apr 27, 2014 at 11:28
- Try not to post code based questions – ArmaGeddON Commented Apr 27, 2014 at 11:28
3 Answers
Reset to default 1you can do this using javascript
add any tag before (generally div or span tag is used) textarea tag
<div id="adduserdata"></div>
<textarea id="txtarea"></textarea>
<input type="button" value="add text" id="add" onclick="showtext()" />
Javascript code would be
function showtext(){
var text = document.getElementById("txtarea");
var showarea = document.getElementById("adduserdata");
showarea.innerHTML=text.value;
}
here is working example
As what you want, thus appending to the <div>
division element, I assume that you will accept this answer (as a summary to all the ments and answers above) :
<!-- This is the HTML Part -->
<div id="text"></div>
<textarea id="new"></textarea>
<input type="button" onclick="appendTextToDiv();" />
<script>
function appendTextToDiv(){document.getElementById("text").innerHTML = document.getElmentById("text").innerHTML + document.getElementById("new").value;}
</script>
This can let you simply append it to the text. Fiddle
This will do if using Jquery (and previously text will stay) :
$('.button').click(function(){
var text = $('textarea').val();
if(text!=''){
$('p').text(text);
}
});
or like this:
$('.button').click(function(){
var text = $('textarea').val();
if(text!=''){
$('<p></p>').text(text).insertBefore('textarea');
}
});
Fiddle
本文标签: javascriptDisplaying textarea content on click of buttonStack Overflow
版权声明:本文标题:javascript - Displaying textarea content on click of button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745532428a2662120.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论