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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php variables passed through javascript function 1

Status
Not open for further replies.

LTeeple

Programmer
Aug 21, 2002
362
CA
I am having difficulty passing/receiving a php variable when I open a new window using the window.open() function.
Here's my code:
User clicks on a link on page:

<a href=&quot;javascript:go(<? echo &quot;$id&quot; ?>)&quot;><? echo &quot;$name&quot; ?></a></font></td>
here's the javascript function (same page):
function go(id){
myurl = 'member.php?myid=' + id;
window.open(myurl,'get','width=645,height=450,resizable=1,scrollbars=yes');
}

I want to keep using the $id variable for the page that will load via window.open() - how do I access the darn thing?
 
You should be able to access it via $_GET['myid'] or $HTTP_GET_VARS['myid']. Or if you have register globals on, just $myid.
I'm assuming that this is what isn't working for you. Is this assumption correct? //Daniel
 
Hi, thanks, your assumption is correct. Unfortunately, it isn't working for me, I believe it has something to do with javascript in the url, when I right-click on the link and open in new window (so I can see the address),

I see the following:
javascript:go(78)
The link isn't in a form, so there's no method - get or post. Do I need to include this link as part of a form so I can access that variable?

I greatly appreciate any insight...
Cheers!
 
No, since when a URL is followed by a ?, the browser assumes that you are passing values to the URL using the GET method.
I guess you could try and change your link to
Code:
<a href=&quot;#&quot; onclick=&quot;go(<?=$id?>);&quot;><?=$name?></a>
It shouldn't make a differnce, but I guess it's worth a shot. //Daniel
 
Okay, got it, thanks so much! :)

Love Tek-Tips!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top