"document.write" questions...

J

John Kopf

I've tried seversl experiments, but the results appear inconclusive...

I write a js function that includes a document.write statement.

If i place that function within a HTML HEAD, I find no results of that
write in the output document.

If I put the same document.write in the BODY, the output appears
(somewhere).

If I put the function within the BODY, the output sometimes appears - is
it supposed to appear at the location of the function or at the location
of the call?

(What I'm trying to do is create a function, whose arguments are a
image-file name and a caption, to create a captioned image within the
document; successive calls would then create a "slide strip".

I know that I could have the function return a (massive) string to feed
to the document.write, thus:
document.write( TableMake( image1.jpg, "caption 1" ) );
document.write( TableMake( image2.jpg, "caption 2" ) );
document.write( TableMake( image3.jpg, "caption 3" ) );
...
....but that seem clumsy especially if there are hundreds of images
(e.g., portraits of a club"s membership),.

Any suggestions as to where to place the function , the document.write
that actually places the object HTML code, and where to invoke the
function eithin the document?

John Kopf
 
E

Evertjan.

John Kopf wrote on 19 dec 2009 in comp.lang.javascript:
I know that I could have the function return a (massive) string to feed
to the document.write, thus:
document.write( TableMake( image1.jpg, "caption 1" ) );
document.write( TableMake( image2.jpg, "caption 2" ) );
document.write( TableMake( image3.jpg, "caption 3" ) );

I do not think you know.

imageX.jpg should be quoted as it is a string litteral.

Are you trying to build a javascript script with javascript?
That is possibel, but inadvisable for the newbe,
and does not add functionality.

Are you trying to do aq document.write() after the page is loaded?
You will trigger an implicid document.open() and destroy the page.

[btw it is custom to start a function name with a lowercase]

Use a simple loop [before the page load is finished]

var n = 2300; // massive??
for (var i=1;i<=n;i++)
tableMake( 'image'+n+'.jpg', 'caption '+n );

tableMake() writes it's return value directly to the page,
you do not need document.write() to do that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top