[Javascript] Javascript echo()?

Scott Reynen scott at randomchaos.com
Thu Oct 4 23:16:55 CDT 2007


On Oct 4, 2007, at 8:23 PM, tedd wrote:

> Hi gang:
>
> I'm currently sending data (the value of s) to another script via the
> html statement:
>
> <a href="img.php?s=<?php echo($value);?>">Click here</a>
>
> However, I need to add another variable, namely a javascript variable.
>
> How can I send both a php and a javascript variable at the same time?
>
> Not to mislead anyone with a better idea, but what I need is
> something in javascript that works like like php's echo().
>
> TIA for any replies.

The closest JavaScript equivalent to echo() is document.write;  
however, that only works within <script> tags, which of course can't  
go within attributes of other tags.  So it would be better (not least  
because it would be possible) to read the href attribute and append  
the JavaScript variable to it before opening the link, e.g.:

<a href="img.php?s=<?php echo($value);?>" onclick="window.open 
( this.getAttribute( 'href' ) + '&t=' + t ); return false;">Click  
here</a>

Peace,
Scott




More information about the Javascript mailing list