I also modified the above script to make it general
formatStr(EL,maxchars)
maxchars is the no of characters per line or the nth character at which wrapping to be done. Here is the same script
function formatStr(EL,maxchars)
// the EL is the target element passed fron the invokin process in the form:
// maxchars is no of characters per line or the nth character at which text to be wrapped. For Ex At 15th character//
// document.getElementById('idofelement');
{
strbuff=EL.innerHTML;
// takes the content of the eleemtn and puts it into a string
newstr='';
startI = 0;
max=maxchars;
str='';
subarr=new Array(parseInt(strbuff.length/max+1));
// creates an array with a length that will hold all max character segments + the final bit.
// in the earlier versio I was using 7 which is incorrect 15 is the required size
for (i=0;i<subarr.length;i++)
{
// this loop creates max character substrings an put them in anarray
subarr[i]=strbuff.substr(startI,max);
startI+=max;
}
for (i=0;i<subarr.length-1;i++)
{
// this loop creates a new string by concatenating the elements in the array
// with an HTML line break tag between each segment
newstr+=subarr[i]+'<br />';
}
str+=subarr[subarr.length-1];
// the final segement is append outside to loop to avoid an extra linefeed
EL.innerHTML=newstr;
// the content of the target element is replaced with the new string
}
<td><div style="width:10pt; word-wrap: break-word;"> asldkjf alsdk jfalskasdf asdf asldfja a</div></td>
If you can use serverside
this should work for you
http://www.php.net/wordwrap