On Fri, 30 Jan 2004 03:59:33 -0600, Ken <kkrolski@wi.rr .com> wrote:
[color=blue]
> How do I force the text generated by a document.write command to wrap
> after a specified number of characters?[/color]
Insert \n into the string to force a new line. For example:
Bonjour à Michael Winter <M.Winter@bluey onder.co.invali d> qui nous a
écrit :[color=blue]
> On Fri, 30 Jan 2004 03:59:33 -0600, Ken <kkrolski@wi.rr .com> wrote:
>[color=green]
>> How do I force the text generated by a document.write command to wrap
>> after a specified number of characters?[/color]
>
> Insert \n into the string to force a new line. For example:
>
> document.write( 'First line\nSecond line');
>
> Mike[/color]
I prefer the "<br>" tag (Html) : document.write( 'First line<br>Second
line');
On Fri, 30 Jan 2004 13:03:51 +0100, Cenekemoi
<tbaudessonENLE VER@harrysoftwa re.ENVELERcom> wrote:
[color=blue]
> Bonjour à Michael Winter <M.Winter@bluey onder.co.invali d> qui nous a
> écrit :
>[color=green]
>> On Fri, 30 Jan 2004 03:59:33 -0600, Ken <kkrolski@wi.rr .com> wrote:
>>[color=darkred]
>>> How do I force the text generated by a document.write command to wrap
>>> after a specified number of characters?[/color]
>>
>> Insert \n into the string to force a new line. For example:
>>
>> document.write( 'First line\nSecond line');[/color]
>
> I prefer the "<br>" tag (Html) : document.write( 'First line<br>Second
> line');[/color]
What is most appropriate depends on the context. The OP didn't specify.
What do I do if the text to be written is a variable and I have no control
of the content?
For example
....<tr><td colspan=2 align=left><fon t size="2">' + text +
'</font></td></tr>...
Ken
"Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
news:opr2k73rl8 5vklcq@news-text.blueyonder .co.uk...[color=blue]
> On Fri, 30 Jan 2004 13:03:51 +0100, Cenekemoi
> <tbaudessonENLE VER@harrysoftwa re.ENVELERcom> wrote:
>[color=green]
> > Bonjour à Michael Winter <M.Winter@bluey onder.co.invali d> qui nous a
> > écrit :
> >[color=darkred]
> >> On Fri, 30 Jan 2004 03:59:33 -0600, Ken <kkrolski@wi.rr .com> wrote:
> >>
> >>> How do I force the text generated by a document.write command to wrap
> >>> after a specified number of characters?
> >>
> >> Insert \n into the string to force a new line. For example:
> >>
> >> document.write( 'First line\nSecond line');[/color]
> >
> > I prefer the "<br>" tag (Html) : document.write( 'First line<br>Second
> > line');[/color]
>
> What is most appropriate depends on the context. The OP didn't specify.
>
> Mike
>
> --
> Michael Winter
> M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)[/color]
Michael Winter a ecrit :[color=blue]
>
> On Fri, 30 Jan 2004 13:03:51 +0100, Cenekemoi
> <tbaudessonENLE VER@harrysoftwa re.ENVELERcom> wrote:
>[color=green]
> > Bonjour à Michael Winter <M.Winter@bluey onder.co.invali d> qui nous a
> > écrit :
> >[color=darkred]
> >> On Fri, 30 Jan 2004 03:59:33 -0600, Ken <kkrolski@wi.rr .com> wrote:
> >>
> >>> How do I force the text generated by a document.write command to wrap
> >>> after a specified number of characters?
> >>
> >> Insert \n into the string to force a new line. For example:
> >>
> >> document.write( 'First line\nSecond line');[/color]
> >
> > I prefer the "<br>" tag (Html) : document.write( 'First line<br>Second
> > line');[/color]
>
> What is most appropriate depends on the context. The OP didn't specify.[/color]
and much better (if is send to a popup for instance)
document.write( 'First line\n<br>Secon d line');
\n will do a return for JS returns on line in html code
<br> will do a return for html returns on page displayed in window's browser
On Fri, 30 Jan 2004 09:22:36 -0600, Ken <kkrolski@wi.rr .com> wrote:
[color=blue]
> What do I do if the text to be written is a variable and I have no
> control of the content?
>
> For example
> ...<tr><td colspan=2 align=left><fon t size="2">' + text +
> '</font></td></tr>...[/color]
Here, using <br> in place of \n would be most appropriate. However, I
would suggest that you avoid breaking lines of text in pages. If the
internal browser area (canvas, if you will) is smaller than you designed
for, your page will look horrible.
|------------|
You could
end
up with text
like
this.
|-------------|
You won't end
up with text
like this.
Instead, try specifying a width for the table cell (and other containers)
and let the browser wrap the contents. Do realise that this advice is from
a general point of view. If you have specific reasons that mean that
wrapping must be forced and cannot be left to the browser, then go ahead
with the use of <br>.
Unfortunately, I cannot use <br> or /n since I do not have control over the
text. I do not know where the sentences should break or where there are
carriage returns.
I tried setting the table and cell widths, but these did not reduce the
width of the cell since the text is greater than the cell width. The
browser increases the cell width to fit the text.
Do I have any other options? commands?
This is a difficult problem but others must of faced it. I figure I must be
missing a command to wrap the text in a document.write statement with a
variable for the text. I expect this should be done often on webpages.
Thanks for the continuing help.
Ken
"Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
news:opr2lh3qku 5vklcq@news-text.blueyonder .co.uk...[color=blue]
> On Fri, 30 Jan 2004 09:22:36 -0600, Ken <kkrolski@wi.rr .com> wrote:
>[color=green]
> > What do I do if the text to be written is a variable and I have no
> > control of the content?
> >
> > For example
> > ...<tr><td colspan=2 align=left><fon t size="2">' + text +
> > '</font></td></tr>...[/color]
>
> Here, using <br> in place of \n would be most appropriate. However, I
> would suggest that you avoid breaking lines of text in pages. If the
> internal browser area (canvas, if you will) is smaller than you designed
> for, your page will look horrible.
>
> |------------|
> You could
> end
> up with text
> like
> this.
>
> |-------------|
> You won't end
> up with text
> like this.
>
>
> Instead, try specifying a width for the table cell (and other containers)
> and let the browser wrap the contents. Do realise that this advice is from
> a general point of view. If you have specific reasons that mean that
> wrapping must be forced and cannot be left to the browser, then go ahead
> with the use of <br>.
>
> Mike
>
> --
> Michael Winter
> M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)[/color]
JRS: In article <PWpSb.3426$2h. 2797@twister.rd c-kc.rr.com>, seen in
news:comp.lang. javascript, Ken <kkrolski@wi.rr .com> posted at Fri, 30
Jan 2004 03:59:33 :-
[color=blue]
>How do I force the text generated by a document.write command to wrap after
>a specified number of characters?[/color]
To do what you ask for : construct, if necessary by concatenation, a
single string X for document.write( X) ; and, in between, do
X = X.replace(/(.{6})/g, "$1<br>")
where 6 represents the specified number and <br> is used to wrap (you
might want \n). If the number is a computed variable, you'll need to
use new RegExp(S1+N+S2) to absorb a string containing the value N.
To break at the last word-breaks before the N'th character will be
harder.
If I'm understanding correctly, you need to format the length out the
context of what the text is.. Why can't you just format the text like you
would any other text within a html page. Put the document.write( ) within
a <td> and control the with of the <td> or put the document.write( ) within
a div and control the with of a div..
Pete
On 2004-01-30 11:26:50 -0800, "Ken" <kkrolski@wi.rr .com> said:
[color=blue]
> Unfortunately, I cannot use <br> or /n since I do not have control over[/color]
the[color=blue]
> text. I do not know where the sentences should break or where there are
> carriage returns.
>
> I tried setting the table and cell widths, but these did not reduce the
> width of the cell since the text is greater than the cell width. The
> browser increases the cell width to fit the text.
>
> Do I have any other options? commands?
>
> This is a difficult problem but others must of faced it. I figure I must[/color]
be[color=blue]
> missing a command to wrap the text in a document.write statement with a
> variable for the text. I expect this should be done often on webpages.
>
> Thanks for the continuing help.
>
> Ken
>
> "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
> news:opr2lh3qku 5vklcq@news-text.blueyonder .co.uk...[color=green]
> > On Fri, 30 Jan 2004 09:22:36 -0600, Ken <kkrolski@wi.rr .com> wrote:
> >[color=darkred]
> > > What do I do if the text to be written is a variable and I have no
> > > control of the content?
> > >
> > > For example
> > > ...<tr><td colspan=2 align=left><fon t size="2">' + text +
> > > '</font></td></tr>...[/color]
> >
> > Here, using <br> in place of \n would be most appropriate. However, I
> > would suggest that you avoid breaking lines of text in pages. If the
> > internal browser area (canvas, if you will) is smaller than you[/color][/color]
designed[color=blue][color=green]
> > for, your page will look horrible.
> >
> > |------------|
> > You could
> > end
> > up with text
> > like
> > this.
> >
> > |-------------|
> > You won't end
> > up with text
> > like this.
> >
> >
> > Instead, try specifying a width for the table cell (and other[/color][/color]
containers)[color=blue][color=green]
> > and let the browser wrap the contents. Do realise that this advice is[/color][/color]
from[color=blue][color=green]
> > a general point of view. If you have specific reasons that mean that
> > wrapping must be forced and cannot be left to the browser, then go[/color][/color]
ahead[color=blue][color=green]
> > with the use of <br>.
> >
> > Mike
> >
> > -- > Michael Winter
> > M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)[/color]
>
>
>[/color]
"Ken" <kkrolski@wi.rr .com> wrote in
news:PWpSb.3426 $2h.2797@twiste r.rdc-kc.rr.com:
[color=blue]
> How do I force the text generated by a document.write command to wrap
> after a specified number of characters?
>
> Thanks for the help.
>
>[/color]
You can try this:
var the_text = "this is the demo text";
var text_pt = the_text.substr ing(5,10);
document.write( text_pt);
The "5" and "10" (5,10) are the zero-based start and end points of what
will be gleaned from the original string.
If your original text variable is long, a for loop could be used to grab
succeeding sections of the string. You just have to be sure you don't grab
anything beyond the length.
Anyway, try that out and see if it will owrk for you.
LJL wrote:
[color=blue]
> "Ken" <kkrolski@wi.rr .com> wrote in
> news:PWpSb.3426 $2h.2797@twiste r.rdc-kc.rr.com:
>
>[color=green]
>>How do I force the text generated by a document.write command to wrap
>>after a specified number of characters?
>>
>>Thanks for the help.
>>
>>[/color]
>
>
> You can try this:
>
> var the_text = "this is the demo text";
> var text_pt = the_text.substr ing(5,10);
> document.write( text_pt);[/color]
and see how I did it there (it doesn't break words, it backs up to the
last space).
[color=blue]
> The "5" and "10" (5,10) are the zero-based start and end points of what
> will be gleaned from the original string.
>
> If your original text variable is long, a for loop could be used to grab
> succeeding sections of the string. You just have to be sure you don't grab
> anything beyond the length.[/color]
Expanding your original code, its output would be this:
Comment