Description While designing websites we often come across situations where we have to display data in limited space programmatically and we have to split data into chunks to accommodate them. However, if we are dealing with meaningful text then the splitting occurs without taking into account grammatical structures and words structures, so we end up loading chunks of texts which are not complete words and thus meaningless. To avoid this we can split text by specifying an identifier character like a space or comma, so that if the particular word is of 10 characters and the space left in the block is 4, the program skips to the next block instead of assigning the first 4 characters of the word. This way we can keep meaningful words whole while splitting data to accommodate them in blocks of varying sizes. |
Please look at the following code NOTES : in javascript part we have two variables We can assign space like ” ” or comma like “,” to the delimiter variable according to the requirement. autostart is a variable which auto start the script to show all chunks automatically. If we want to auto start the script we have to assign ( autostart =1 ) else assign (autostart = 0 ), when autostart = 0 we have to click on Next > > link to see the next chunk. |
var delimiter = ","; var autostart = 1; function puttext_start() { puttext1('100') } function puttext1(le) { var str = document.getElementById('stringarea').innerHTML; var len = str.length; document.getElementById('stringarea').innerHTML =str.substr(0,parseInt(len)-1); if(le != 0) { var newle = parseInt(le)-1; window.setTimeout("puttext1('"+newle+"')",12); } else { puttext(); } } function puttext() { var data = document.getElementById('textdata').value; var newdata = data.split(delimiter); // whitepace as delimiter var c = newdata.length; if(delimiter == ' ') c = c - 1; document.getElementById('maxsplit').value = c; //we have to split it in different parts of 30 characters in a part //max 3 if exids then 2 var getpart = document.getElementById('stringpart').value; if(getpart == c) { document.getElementById('stringpart').value = 0; getpart = 0; } else { document.getElementById('stringpart').value = parseInt(document.getElementById('stringpart').value)+1; } var string ='' var block = 0; for(var i = 0;i