View Full Version : Resolved Displaying items as individual lines in a textarea using js

05-22-2009, 10:51 AM
I am trying to use the contents of array to populate a <textarea>, or to appear in a 'box'.

The selection from the array is defined by a SELECT box.

I can get everything working with the exception of the line 'formatting' for the 'textarea'.

To enable me to test it I am creating a variable called telephones from all the relevant elements and this is displaying in the 'textarea'.

However, I want each element of the array to be shown as a separate line in the 'textarea'.

This is my code that gets the appropriate individual elements from the array.

function populatePhone() {
var selObj = document.getElementById('phoneSelect');
var telephones="";
var foundPhone = false;
var phoneLineArray = phone.split("|"); // Split into lines
var optionCntr = 1;
for (var loop = 0; loop < phoneLineArray.length; loop++) {
lineArray = phoneLineArray[loop].split(":");
stateCode = TrimString(lineArray[0]);
phoneCode = TrimString(lineArray[1]);
phoneName = TrimString(lineArray[2]);
if (document.getElementById('stateSelect').value == stateCode && stateCode != '' ) {
foundPhone = true;

Can somebody, more proficient in javascript than me, tell me how I can achieve this.