473,594 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Document.write

Ken
How do I force the text generated by a document.write command to wrap after
a specified number of characters?

Thanks for the help.
Jul 20 '05 #1
11 2658
On Fri, 30 Jan 2004 03:59:33 -0600, Ken <kk******@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');

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
Bonjour à Michael Winter <M.******@bluey onder.co.invali d> qui nous a
écrit :
On Fri, 30 Jan 2004 03:59:33 -0600, Ken <kk******@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');

Mike


I prefer the "<br>" tag (Html) : document.write( 'First line<br>Second
line');

--
Cordialement, Thierry ;-)

Jul 20 '05 #3
On Fri, 30 Jan 2004 13:03:51 +0100, Cenekemoi
<tb************ ***@harrysoftwa re.ENVELERcom> wrote:
Bonjour à Michael Winter <M.******@bluey onder.co.invali d> qui nous a
écrit :
On Fri, 30 Jan 2004 03:59:33 -0600, Ken <kk******@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');


I prefer the "<br>" tag (Html) : document.write( 'First line<br>Second
line');


What is most appropriate depends on the context. The OP didn't specify.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4
Ken
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.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...
On Fri, 30 Jan 2004 13:03:51 +0100, Cenekemoi
<tb************ ***@harrysoftwa re.ENVELERcom> wrote:
Bonjour à Michael Winter <M.******@bluey onder.co.invali d> qui nous a
écrit :
On Fri, 30 Jan 2004 03:59:33 -0600, Ken <kk******@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');


I prefer the "<br>" tag (Html) : document.write( 'First line<br>Second
line');


What is most appropriate depends on the context. The OP didn't specify.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 20 '05 #5
@SM


Michael Winter a ecrit :

On Fri, 30 Jan 2004 13:03:51 +0100, Cenekemoi
<tb************ ***@harrysoftwa re.ENVELERcom> wrote:
Bonjour à Michael Winter <M.******@bluey onder.co.invali d> qui nous a
écrit :
On Fri, 30 Jan 2004 03:59:33 -0600, Ken <kk******@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');


I prefer the "<br>" tag (Html) : document.write( 'First line<br>Second
line');


What is most appropriate depends on the context. The OP didn't specify.


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

--
******** (enlever/remove [OTER_MOI] du/from reply url) *******
Stéphane MORIAUX : mailto:st****** *************** @wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
*************** *************** *************** *************** **
Jul 20 '05 #6
On Fri, 30 Jan 2004 09:22:36 -0600, Ken <kk******@wi.rr .com> wrote:
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>...


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.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #7
Ken
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.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...
On Fri, 30 Jan 2004 09:22:36 -0600, Ken <kk******@wi.rr .com> wrote:
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>...


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.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 20 '05 #8
JRS: In article <PW************ ****@twister.rd c-kc.rr.com>, seen in
news:comp.lang. javascript, Ken <kk******@wi.rr .com> posted at Fri, 30
Jan 2004 03:59:33 :-
How do I force the text generated by a document.write command to wrap after
a specified number of characters?


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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 20 '05 #9
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" <kk******@wi.rr .com> said:
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.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...
On Fri, 30 Jan 2004 09:22:36 -0600, Ken <kk******@wi.rr .com> wrote:
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>...


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.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)


Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2863
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>"); document.write("<OPTION VALUE='0.345066110642241'>Argentina Peso </OPTION>"); document.write("<OPTION VALUE='0.790200069503053'>Australia Dollar
2
2376
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of copying/pasting everytime I change it, I figure this will be better, as I only change it once. The problem is, document.write doesn't handle multiple lines very well, so I was wondering what is the best way to do this? Maybe there is even a better...
14
4102
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as it's being written into the page. Is there a way that I can view what is being placed into the page, instead of, or in addition to the javascript code?
4
2944
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400, like DOS, uses memory-mapped display, two bytes per character (one char byte and one attribute byte). We can get the screen offset allright, and I've written a javascript which does the math to convert the offset into row/col (i.e. left, top)...
2
5759
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
11
460
by: Tony | last post by:
Is it me, or is document.write just about the most abused js function? Maybe, like goto, js would be better without it? Is there any good reason to use it? Because I'm having a hard time seeing any... Maybe my imagination just isn't good enough :)
1
7534
by: anupamaavadutha | last post by:
hi all, iam new to javascript. i have problem calling javascript functions.iam designing a calender page.here is my code. <%@ page import='java.io.*,java.util.*,java.sql.*,javax.servlet.*,javax.servlet.http.*' session='true'%> <%@ page import='java.text.*'%> <html> <script language='javascript'> function backward() { alert("hello"); }
8
7090
by: Mateusz Viste | last post by:
Hi, I am trying make some multimedia files playable from my website. So far, I am able to generate dynamically a new page containing the right <embed> section. However, when I load my script, it overwrites the current page. Is there any way I could load a new tab or window, and put the new content into it? Here is the script I am using right now:
1
3808
by: celeroSolutions | last post by:
This code works in my site in IE, but not in FireFox, and I'm stuck as to why! Any ideas? (The image paths are correct, I've tested these.) <script language="javascript" type="text/javascript"> <!-- var strBGCol = "#ADCED7"; document.write("<table border='0' width='100%' cellpadding='0' cellspacing='0'>"); document.write("<tr>");
0
7882
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6669
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5836
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3871
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3905
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2391
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.