Nell'esempio di prima e´sbagliata qualche lettera (e un -1), ma ecco una applicazione che funziona
Codice PHP:
<html>
<head>
<title>jslab</title>
<script language="javascript" type="text/javascript">
<!--
function prep(sorg,dest) {
str = document.getElementById(sorg).innerHTML;
destStr = ""; // definizione della stringa di destinazione;
strLen = str.length;
rowLen = 50; // rowLen e´ il numero di caratteri che vuoi per ogni riga;
strRest = strLen%rowLen;
for (var i=0; i<(strLen-strRest); i+=rowLen) { destStr += str.substring(i, (i+rowLen)) + "
\n"; }
document.getElementById(dest).innerHTML = destStr;
}
//-->
</script>
</head>
<body>
<input type="button" value="prep" onclick="prep('sorg','dest');">
Layer sorgente:
<div id="sorg" style="background-color: #def;">parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo,
parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo,
parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo,
parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo, parole del testo da compilare con tag BR in fondo,
</div>
Layer di destinazione:
<div id="dest" style="background-color: #efd;"></div>
</body>
</html>