Send variable from javascript to php?

Reply

Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Send variable from javascript to php?

 
0
  #1
Apr 4th, 2008
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:

  1. <a href="javascript:
  2. 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 <a href="my_form.php?value=25">Click Here</a>

But is there a way I can pass a variable through that link with the java script I've got?
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 187
Reputation: phper is an unknown quantity at this point 
Solved Threads: 15
phper's Avatar
phper phper is offline Offline
Junior Poster

Re: Send variable from javascript to php?

 
0
  #2
Apr 4th, 2008
Try adding ?value=25 on to the window.open function.

  1. <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.
If my post is useful please add to my reputation.
Thanks.

Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: Send variable from javascript to php?

 
0
  #3
Apr 4th, 2008
Originally Posted by phper View Post
Try adding ?value=25 on to the window.open function.

  1. <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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: Daedal is an unknown quantity at this point 
Solved Threads: 11
Daedal's Avatar
Daedal Daedal is offline Offline
Light Poster

Re: Send variable from javascript to php?

 
0
  #4
Apr 4th, 2008
Originally Posted by nathanpacker View Post
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;
Last edited by peter_budo; Apr 5th, 2008 at 1:32 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: Send variable from javascript to php?

 
0
  #5
Apr 4th, 2008
Originally Posted by Daedal View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: Daedal is an unknown quantity at this point 
Solved Threads: 11
Daedal's Avatar
Daedal Daedal is offline Offline
Light Poster

Re: Send variable from javascript to php?

 
0
  #6
Apr 4th, 2008
Originally Posted by nathanpacker View Post
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';
Last edited by peter_budo; Apr 5th, 2008 at 1:32 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC