Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I wanna get textarea's each line text into div. Below is my code but problem is that when I'm clicking second time on button then old and new values is being added.

I wanna show only current values on textarea even if i click so many time.

 /* Preview Details */
$('.btn-preview-details').on('click', function(){

/* preview text area's each line */
function previewDetailsText(){
    var getVal = $('#detailText').val();
    if(getVal != ""){
        var getText = getVal.split('\n');
        var items=new Array()
        var counter = 0
        for(var i = 0; i < getText.length; i++){
            /* using lines[i] which will give you each line */

<textarea class="span12" name="detailText" id="detailText" rows="6"></textarea>
<button type="button" class="btn btn-inverse btn-preview-details">Preview</button>

Thanking You.

dont use append method for this. Try createhtml method. it should work.
Share this answer
/* preview text area's each line */
function previewDetailsText() {
var getText = $('#detailText').val().split('\n');

var items = new Array();
var counter = 0;
if(getText != ""){
for(var i = 0; i < getText.length; i++){
var text = getText[i];
if(text != ""){
//IsDataExist = true;
} else {
Share this answer

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