[Javascript] Javascript echo()?
Scott Reynen
scott at randomchaos.com
Fri Oct 5 15:36:58 CDT 2007
On Oct 5, 2007, at 2:31 PM, Hassan Schroeder wrote:
> tedd wrote:
>
>>>> How can I send both a php and a javascript variable at the same
>>>> time?
>
>> Is there a way to tie an open window to javascript's window object?
>> Or, perhaps another solution to the original problem?
>
> I'm totally mystified what "window.open" has to do with the original
> question, but in any case, this should do it --
>
> function add_my_value(val) {
> document.getElementById("x").href += "&t=" + val;
> }
>
> <a id="x" href="foo.html?s=bar">something</a>
The above would work fine if the value is determined by an event that
happens only once, but otherwise you'll get multiple t values in the
query string. To prevent this possibility, I would wait to set the
query string in onclick, so it only happens once. I just used
window.open out of force of habit since that's what I'm usually doing
in an onclick event. But Hassan is right, that really doesn't make
much sense here. To work like a normal link (opening in the same
window), it would be better to do window.location, e.g.:
<a href="img.php?s=<?php echo($value);?>" onclick="window.location =
this.getAttribute( 'href' ) + '&t=' + t; return false;">Click
here</a>
Peace,
Scott
More information about the Javascript
mailing list