Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a textarea. the value is inserted in the textarea on the click of a button
JavaScript
function addText(elId,text) {
	if(document.getElementById("NewJudge").value != "")
	{
	var text_area_id = document.getElementById("hc_judge");
    var judge_name =(document.getElementById("NewJudge").value + "  , ") ;
    var txt = document.createTextNode(judge_name);
    text_area_id.appendChild(txt);
    document.getElementById("NewJudge").value ="";
	}
}

I used ',' to seperate values in the textarea. but the new values should be in a new line.
I searched the net and found that '& #13; & #10;' is used to add new line in textarea. But when I use this code
XML
<pre lang="Javascript">
function addText(elId,text) {
    if(document.getElementById("NewJudge").value != "")
    {
    var text_area_id = document.getElementById("hc_judge");
    var judge_name =(document.getElementById("NewJudge").value + "  & #13;& #10; ") ;
    var txt = document.createTextNode(judge_name);
    text_area_id.appendChild(txt);
    document.getElementById("NewJudge").value ="";
    }
}
</pre>
.
it keeps the text as it is.
i purposely put space between & # as it creates a new line here too :D
but when used in code it isnt working. Please help. Thanks in advance :)
Posted

1 solution

you can use '\n ' as new line character.

var judge_name =(document.getElementById("NewJudge").value + '\n ') ;
 
Share this answer
 
Comments
pradnyaa 3-Jul-14 0:45am    
tnxx for the help.. its working :)

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