Click to See Complete Forum and Search --> : Two line breaks in variables in javascript
blurpop
05-04-2007, 02:02 PM
Hi, how do I create line breaks for variables to show a double space on my page?
Here's part of the var:
var hello = "1. hello goodbye \n2. hello sayonara \n3. hello only"
i added \n for one line break, but i need to to have space in between...please help...
samanyolu
05-04-2007, 02:11 PM
<body>
<div id="divid"></div>
<script type="text/javascript">
var hello = "1. hello goodbye \n\n2. hello sayonara \n\n3. hello only"
alert(hello);
var hello2 = "1. hello goodbye <br><br>2. hello sayonara <br><br>3. hello only"
var el = document.getElementById('divid');
el.innerHTML = hello2;
</script>
blurpop
05-04-2007, 02:30 PM
thanks! but let's say the there are multiple vars to auto populate a text area, and i just wanted double spaces? how do i simplify this formula? so -
var hello = "1. hello goodbye \n\n2. hello sayonara \n\n3. hello only"
var hello = "1. hello goodbye \n\n2. hello sayonara \n\n3. hello only"
var hello = "1. hello goodbye \n\n2. hello sayonara \n\n3. hello only"
var hello = "1. hello goodbye \n\n2. hello sayonara \n\n3. hello only"
var hello = "1. hello goodbye \n\n2. hello sayonara \n\n3. hello only"
var hello = "1. hello goodbye \n\n2. hello sayonara \n\n3. hello only"
and i want double spaces on these variables to display on a text area...please advise
JMRKER
05-04-2007, 04:01 PM
Short example:
document.getElementById('TextAreaId').value = '';
for (var i=0; i<6; i++) {
document.getElementById('TextAreaId').value
+= "1. hello goodbye \n\n2. hello sayonara \n\n3. hello only";
}
blurpop
05-05-2007, 10:45 AM
Thanks so much! Actually, just putting \n\n was working on my end...It didn't at first because of cache. Thanks again!