mickeymouse Posted December 1, 2019 Share Posted December 1, 2019 How do I pass a parameter (myparam) to the page I'm calling via a function. function ancesterF(myparam) {location.href=\"FT_Search2.php\";return false; window.open(location.href); return false;} Tks Link to comment Share on other sites More sharing options...
dsonesuk Posted December 1, 2019 Share Posted December 1, 2019 Querystring such as FT_Search2.php?param=myparam Or in a php session. Link to comment Share on other sites More sharing options...
mickeymouse Posted December 2, 2019 Author Share Posted December 2, 2019 (edited) Thank you dsonesuk. I should also have asked you how do I capture the param in my called page. Edited December 2, 2019 by mickeymouse Link to comment Share on other sites More sharing options...
dsonesuk Posted December 2, 2019 Share Posted December 2, 2019 $getmyparam=$_GET['param']; Link to comment Share on other sites More sharing options...
mickeymouse Posted December 2, 2019 Author Share Posted December 2, 2019 I tried that but I end up with the value of my $getmyparam being equal to "myparam" instead of the value passed which in my test case is "10006" In my calling function, I confirm the value of "myparam" and it is "10006". CALLING CODE: function ancesterF(myparam) {alert(myparam); <----------------------------------------------------------------------------------This confirms the value "10006" location.href='FT_Search2.php?param=myparam';return false; window.open(location.href); return false;} RECIEVING CODE: $getmyparam =$_GET['param']; print("getmyparam"); <------------------------------- Result = "myparam" not "10006" Link to comment Share on other sites More sharing options...
Makwana Prahlad Posted December 30, 2019 Share Posted December 30, 2019 Hello, @mickeymouse Please try this code for passing parameter into URL and to get parameter in current page and also for redirected page. To get parameter value in current page use this code : <?php $url = 'http://www.geeksforgeeks.org/register?name=Demo&email=demo@gmail.com'; $url_components = parse_url($url); parse_str($url_components['query'], $params); echo ' Hi '.$params['name'].' your emailID is '.$params['email']; ?> To get parameter value for redirected page use this code : <?php $name = $_REQUEST['name']; $email = $_REQUEST['email']; echo " Hi ".$name." your emailId is ".$email; ?> For both code output will be : Hi Demo your emailId is demo@gmail.com I hope above information will be useful for you. Thank you. Link to comment Share on other sites More sharing options...
dsonesuk Posted December 30, 2019 Share Posted December 30, 2019 He is passing the varible as a string, when he should concatenate the variable after the string up to equals sign. location.href='FT_Search2.php?param='+myparam; Link to comment Share on other sites More sharing options...
mickeymouse Posted December 31, 2019 Author Share Posted December 31, 2019 I'm using the following according to dsonesuk advice and it works fine.. To pass the parameter: function ancester(myparam) {if(myparam==''){return false;} location.href='FT_Search2.php?param='+myparam;return false; window.open(location.href); return false;} To get the parameter: {$reqref=$_GET['param'];} Thanks for the help! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now