Many times it is required to split a long continuous string or text basis of the width of the element in pixels. I had found a good solution on web and redesigned it to make it generic and cross-browser compatible.
You just require to call this javascript function
wrapText ( text , lengthInPixels , splitter )
Following is the usage of the function
<html>
<script language=”javascript” src=”wrapText.js”></script>
<body>
<input id=”txt” size=”150″ /><input type=”button” onclick=”document.getElementById(‘lbl’).innerHTML=wrapText ( document.getElementById(‘txt’).value , 200 , ‘<br/>’ );” value=”Wrap Text” />
<div id=”lbl”></div>
</body>
</html>
[download id=”4″]
Enjoi!