Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can you align colums in a mutiple select box?

Status
Not open for further replies.

beeka

Programmer
Apr 3, 2002
1
GB
Hi,

I have a selection List box. Each row in it is made up of three different Strings, eg.

row1: cats black large
row2: dog brown small
row3: etc...

But the different Strings can be of varying lengths. I want to align them with tabbed spaces or something similar.

Does anyone have any ideas on how to do this??

Thanks
Beeka
 
1. handy ;]

2. thru javascript:

this script is huge & jurky, but anyways:
Code:
<script>
//array of strings to be alligned
arr=[
&quot;abb ghjk lk&quot;,
&quot;dfehj njiokp klpoi&quot;,
&quot;qwerty jkoltornpop ssuka&quot;
];
len=arr.length;

//array for max lengths
maximum=[];
//array for arr's splited values
splitted=[];
for (jj=0; jj<len; jj++){
  splitted[jj] = arr[jj].split(/\s/,3);
  cur=splitted[jj]; 
  curlen=cur.length
  if (jj==0){//setting max values
    for (kk=0; kk<curlen; kk++){
      maximum[kk]=cur[kk].length; 
    }
  }
  else {
//if (jj>0), check if we have to reset max values
    for (kk=0; kk<curlen; kk++){
	  maxcur=maximum[kk];
	  curkl=cur[kk].length;
	  maximum[kk]=(curkl>maxcur)?curkl:maxcur
	}
  }
}
/*
//see the maximum lengths we have by now
rez=&quot;maximal lengths:\n&quot;;
for (ll=0; ll<maximum.length; ll++){rez+=ll+&quot;: &quot;+maximum[ll]+&quot;\n &quot;;}
alert(rez);
*/

//delimiter for aligning (space)
del=&quot; &quot;;

for (ii=0; ii<arr.length; ii++){
for (m=0; m<maximum.length; m++){
_tmp=splitted[ii][m].length;
_max=maximum[m];
while (_tmp<_max){
//so called &quot;aligning&quot; :)
//sorry, it is not something vey genius..
_curItem=splitted[ii][m]
_curItem=del+_curItem;
_tmp++;
//use _curItem+=del if you want to left-align them
}
}
arr[ii]=splitted[ii].join(&quot; &quot;);
}

//just checking what we have..
document.write(&quot;<pre>&quot;+arr[0]+&quot;<br>&quot;+arr[1]+&quot;<br>&quot;+arr[2]+&quot;</pre>&quot;)
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top