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:
XML
Hi

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(){
    PopupContainer('.modal.preview-details-popup');
    previewDetailsText();
});

/* 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 */
            $('.preview-text').append('<li>'+getText[i]+'</li>');
        }
    }
}

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



Thanking You.
Posted

dont use append method for this. Try createhtml method. it should work.
 
Share this answer
 
/* preview text area's each line */
function previewDetailsText() {
$('.preview-text').html("");
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 != ""){
$('.preview-text').append('<li>'+text+'</li>');
}
}
//IsDataExist = true;
} else {
$('.preview-text').html("");
}
}
 
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