Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.write Shortcut

Status
Not open for further replies.

Bignewbie

Programmer
Feb 22, 2001
351
0
0
PH
Hi guys,

I know i have read this somewhere but i cant find the book or a site that states this:

in ASP the shortcut for response.write is: <%=%>

what is the shortcut for document.write in Javascript?

kinda easy but i havent found my book, im hoping u guys know....


thanks!


biggie
 
If I got you right, you want to insert document.write statement into html code. You have to do it like this:
. . .
<script>document.write('...')</script>
. . .

Use proper terminology because others can be confused by what you say. There are no any 'shortcuts' here.
 
I said shortcut 'coz that;s exactly what i am looking for!

you are right, what i want to do is something like so:

. . .
<script>document.write('...')</script>
. . .


but i once found in a book that gives a shortcut for document.write which if i remember if correctly looks like this:

. . .
<?=document.write('...')?>
. . .

Unfortunately, im not sure if this is the correct syntax! that's why im asking ppl here if they know . . .


biggie



 
These:
<? and ?>
are starting and ending tags for PHP scripts.
There are no such things for javascript.
 
hey,

I know that! that's why i need clarification!

never mind, I'll find it myself!

thanks for &quot;trying&quot; anyway!


biggie

 
Like starway said, there IS no shortcut for document.write(). I wrote me own using:

function wr(onestring)
{
document.write(onestring);
}

but that has to be included on every page where you use the shortcut.
 
I went one better than that... I defined a
Code:
.write()
method on the
Code:
String.prototype
object. You can see it at (you'll find my navigable calendar component there too!).

Code:
Function writeFn(doc)
{
  if(!doc)doc=document;
  doc.write(this);
  return (this);
}
String.prototype.write=writeFn;

Once defined (externally in dynamicHTML3.js), writing strings is as easy as adding
Code:
.write()
onto 'em!

Code:
&quot;Hello World&quot;.write();[\code]

For that matter, I defined [code].alert()
and
Code:
.status()
similarly:

Code:
function alertFn(win)
{
  if(!win)win=window;
  win.alert(this);
  return (this);
}
String.protocol.alert=alertFn;

function statusFn(win)
{
  if(!win)win=window;
  win.status=this;
  return (this);
}
String.protocol.alert=alertFn;

Try this on for size...

Code:
&quot;Hello World!&quot;.alert().status().write();
[thumbsup2]

First, it pops up an alert. Then after it is dismissed, the status bar message displays and finally the page text is written.

Cool, huh? ::)

You may go to to view my latest improvements to a fully-navigable cross-browser calendar component. If you decide to use my dynamicHTML3.js library (just File|Save As from the angelfire page), please credit me somewhere and feel free to email me any questions or comments.

mailto:richard.renfrow@juno.com
 
RichardEdwards, you have too much time on your hands[lol] kidding, that's is pretty cool!

Bignewbie, chill out man, getting frustrated is not the way to go. No offense but the question got real fuzzy when you pulled the php tags out as a example. You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top