Word spacing

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
[n00b]
Forum Commoner
Posts: 34
Joined: Sat Mar 20, 2004 7:06 pm

Word spacing

Post by [n00b] »

How can make text in a cell that has no spacing to be automatically "wrapped"?
I`m writing a shoutbox script for my site that will appear on a box like 140 or 150 px long. The problem is, when a user writes a word that has length more than the cell can fit (like "this_is_a_long_word_and_it_does_not_fit_in_the_cell" or "aaaaaaaaaaaaaaaaaaaaaaaa") the cell gets stretched messing all the other cells and tables. So, how can make that cell wrap text so text like this:
this_is_a_long_word_and_it_does_not_fit_in_the_cell
appears like this:
this_is_a_long_word_and
_it_does_not_fit_in_the_cell

Thanks :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

searching the manual should have turned up: [php_man]wordwrap[/php_man] :roll:
[n00b]
Forum Commoner
Posts: 34
Joined: Sat Mar 20, 2004 7:06 pm

Post by [n00b] »

isnt this possible in HTML? :roll:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

not anymore. used to be able to use the <wbr> tag, but that doesn't exist anymore.

you can use CSS overflow attribute potentially.
User avatar
no_memories
Forum Contributor
Posts: 145
Joined: Sun Feb 01, 2004 7:12 pm
Location: New York City

Post by no_memories »

I think u need a java script, which is used in this forum software of all things.

Code: Select all

//http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close) &#123;
var selLength = txtarea.textLength;
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) 
	selEnd = selLength;
	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
&#125;
Not sure if this is the entire piece of code required, but the mozedit script can be purchased at the website in the code for around 2 bucks U.S. - providing you want the word wrap that bad on your textareas. :)
Post Reply