Solved

wrap/break text

Posted on 2008-06-19
6
1,271 Views
Last Modified: 2010-04-21
i am trying to wrap the long text which has no white space inbetween the letters within the width of the td using style syntax.
 it works fine in IE. but fails in ff.  
 so i need to break the text and insert a break or new row after each 200 characters using javascript.
 pl help.
<HTML>
<HEAD>
<style>
  td {	 word-break:break-all; 
		 word-wrap:break-word;
		 white-space:pre-line;
      }
</style>
 </HEAD>
 <BODY>
  <TABLE width="600px" border="1">
  <TR>
        <TD width="400px">fsdafsdddddddddddddddddddddddddddddgfgggggggggggggggggggggggggggggggggggggggggggggggd</TD>
        <TD width="200px">ffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffff</TD>
  </TR>
  <TR>
        <TD>fffffffffffffffffffffffffffffffffffffffffff</TD>
        <TD>ddddddddddddddd</TD>
  </TR>
  <TR>
        <TD>dsafdfas</TD>
        <TD>dasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss</TD>
  </TR>
  </TABLE>
 </BODY>
</HTML>

Open in new window

0
Comment
Question by:vidhubala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 14

Expert Comment

by:ali_kayahan
ID: 21824173


<HTML>
<HEAD>
<style>
  td {	 word-break:break-all; 
		 word-wrap:break-word;
		 white-space:pre-line;
      }
</style>
<script language="javascript">
function wrap(text) {
	var z = 100 ;
	var ttl = text.length / z ;
	ttl = (Math.round(ttl) + 2) * z ;
	for(var i = z;i < ttl ;i += z) {
	document.write(text.substring(i-z,i)+"<br>") ;
	}
}
</script>
 </HEAD>
 <BODY>
  <TABLE width="600px" border="1">
  <TR>
        <TD width="400px"><script>wrap("ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffff")</script></TD>
        <TD width="200px"></TD>
  </TR>
  </TABLE>
 </BODY>
</HTML>

Open in new window

0
 

Author Comment

by:vidhubala
ID: 21824194
good attempt. not very useful. cant put script tag in each td.
0
 

Author Comment

by:vidhubala
ID: 21824216
also its not breaking the word evenly.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vidhubala
ID: 21824356
fails in Firefox.
 tried another method too.. it fails in firefox.pl help.
<HTML>
<HEAD>
<style>
  td {   word-break:break-all; 
                 word-wrap:break-word;
                 white-space:pre-line;
      }
</style>
<script language="javascript">
function wrap() {
        var text = document.getelementsbytagname('td'); 
		var z = 100 ;
        var ttl = text.length / z ;
        ttl = (Math.round(ttl) + 2) * z ;
        for(var i = z;i < ttl ;i += z) {
        document.write(text.substring(i-z,i)+"<br>") ;
        }
}
</script>
 </HEAD>
 <BODY>
  <TABLE width="400px" border="1">
  <TR>
      <TD width="400px" id="one">	  ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffff</TD>
      <TD width="200px">ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffff</TD>
  </TR>
  <TR>
      <TD width="400px" id="one">ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffff</TD>
      <TD width="200px">ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffff</TD>
  </TR>
  </TABLE>
 </BODY>
</HTML>

Open in new window

0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 21940769
Try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
 "http://www.w3.org/TR/REC-html40/strict.dtd">
 
 
<HTML>
<HEAD>
<style>
  td {   word-break:break-all; 
                 word-wrap:break-word;
                 white-space:pre-line;
			  
      }
</style>
<script language="javascript">
function wrap() {
	var data = document.getElementsByTagName('td'); 
	var  desiredLength =40 ;
	var delimiter="<br/>";
	for( var i=0; i < data.length; ++i )
	{
		cellLength=data[i].innerHTML.length
		if( desiredLength < cellLength )
		{
			var counter=0;
			var output="";
			while( counter < cellLength )
			{
				output += data[i].innerHTML.substr(counter,desiredLength) + delimiter;
				counter+= desiredLength;
			}
			data[i].innerHTML=output;
		}
	}
}
window.onload=wrap;
</script>
 </HEAD>
 <BODY>
<center>
  <TABLE width="600" border="1">
  <TR>
      <TD width="400px" id="one">	  ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffff</TD>
      <TD width="200px">ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffff</TD>
  </TR>
  <TR>
      <TD width="400px" id="one">ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffff</TD>
      <TD width="200px">ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggfffff</TD>
  </TR>
  <TR>
      <TD width="400px" id="one">gfffff</TD>
      <TD width="200px">gg</TD>
  </TR>
  </TABLE></center>
 </BODY>
</HTML>

Open in new window

0
 

Author Closing Comment

by:vidhubala
ID: 31468869
great. thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Only allow one check box 17 39
Clear input text 15 26
How to get text of href without any ID using Javascript 9 23
Html using "Or" in condition 3 25
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question