954,148 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Send variable from javascript to php?

Wasn't sure whether to put this in java or php, so I'm putting it here. I have a bit of java that opens a php page in a popup window, using this code:

<a href="javascript:
void(0) "onclick="window.open ('my_form.php','linkname','height=465, width=400, left=550, top=150, scrollbars=no')">Click Here</a>


So that code opens up "my_form.php" in a pop-up window. But I need to pass a value to that php page. Like with PHP, I could simply say Click Here

But is there a way I can pass a variable through that link with the java script I've got?

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

Try adding ?value=25 on to the window.open function.

<a href="javascript:void(0);" onclick="window.open ('my_form.php?value=25','linkname','height=465, width=400, left=550, top=150, scrollbars=no')">Click Here</a>


I have done something like this previously and it has worked.

phper
Posting Whiz in Training
213 posts since Nov 2006
Reputation Points: 22
Solved Threads: 19
 

Try adding ?value=25 on to the window.open function.

<a href="javascript:void(0);" onclick="window.open ('my_form.php?value=25','linkname','height=465, width=400, left=550, top=150, scrollbars=no')">Click Here</a>

I have done something like this previously and it has worked.

Great idea. I tried that, and for some reason, it didn't work.

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 
Great idea. I tried that, and for some reason, it didn't work.

How are you calling the variable in PHP on my_form.php?

//this will set $value to the $_GET variable 'value' if it is there else set it to default of 'NOTHING POSTED' $value = (isset($_GET[value])) ? $_GET[value] ? 'NOTHING POSTED';

//do something with $value echo "Your age is ". $value;

Daedal
Junior Poster in Training
75 posts since Apr 2008
Reputation Points: 23
Solved Threads: 12
 

How are you calling the variable in PHP on my_form.php?

//this will set $value to the $_GET variable 'value' if it is there else set it to default of 'NOTHING POSTED' $value = (isset($_GET[value])) ? $_GET[value] ? 'NOTHING POSTED';

//do something with $value echo "Your age is ". $value;

Well, in the past, I haven't had to call it other than it's already set in a variable. Usually, when I create a link like "my_link.php?value=3", then in the page, my_link.php, I can simply echo $value, and it would echo "3". But I'll try what you've put.

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 
Well, in the past, I haven't had to call it other than it's already set in a variable. Usually, when I create a link like "my_link.php?value=3", then in the page, my_link.php, I can simply echo $value, and it would echo "3". But I'll try what you've put.

I had a typo in my post, the second question mark should have been a colon. $value = (isset($_GET[value])) ? $_GET[value] : 'NOTHING POSTED';

Daedal
Junior Poster in Training
75 posts since Apr 2008
Reputation Points: 23
Solved Threads: 12
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You