ajoo Posted June 29, 2014 Share Posted June 29, 2014 Hi all ! I wish to post the value of an auto submit dropdown value to another page, be redirected to that page, and use it on that page. I am unable to achieve this in php and so I tried as :-follows:- dropdown.php <form method="post" action = dropdownaction.php> <select name="myselect" onchange="this.form.submit();"> <option>blue</option> <option>red</option> </select> </form> and now I need the equivalent of dropdownaction.php <?php if(isset($_POST(['myselect']))) echo " I am selected".$_POST['myselect']; ?> Please can someone tell me how I may retrieve the value of 'myselect' in the dropdownaction.php after being redirected to it. Thanks loads. Link to comment https://forums.phpfreaks.com/topic/289332-posting-the-value-of-an-auto-submit-drop-down-list-to-another-page/ Share on other sites More sharing options...
Ch0cu3r Posted June 29, 2014 Share Posted June 29, 2014 Your if statement should be if(isset($_POST['myselect'])) echo " I am selected".$_POST['myselect']; Also always enclose HTML attribute values in quotes too <form method="post" action="dropdownaction.php"> ... Link to comment https://forums.phpfreaks.com/topic/289332-posting-the-value-of-an-auto-submit-drop-down-list-to-another-page/#findComment-1483359 Share on other sites More sharing options...
ajoo Posted June 29, 2014 Author Share Posted June 29, 2014 Hi Ch0cu3r, Thanks for the reply. I'll remember to enclose the HTML attributes in quotes. Thanks. However this does not work. ( How I wished it would ). But so far as I have read this does not work and we have to use javascript and we have to use the onChange event, like I have done in dropdown.php. The rest ( envoking the value of myselect) in and after being redirected to dropdownaction.php , however is still a mystery to me. Thanks !! Link to comment https://forums.phpfreaks.com/topic/289332-posting-the-value-of-an-auto-submit-drop-down-list-to-another-page/#findComment-1483361 Share on other sites More sharing options...
Ch0cu3r Posted June 29, 2014 Share Posted June 29, 2014 What? I do not understand your post. Can you explain what it is you're trying to do? Link to comment https://forums.phpfreaks.com/topic/289332-posting-the-value-of-an-auto-submit-drop-down-list-to-another-page/#findComment-1483362 Share on other sites More sharing options...
fastsol Posted June 29, 2014 Share Posted June 29, 2014 What isn't it doing? I tried the code with the changes Ch0cu3r suggested and it works as I expected it too. Link to comment https://forums.phpfreaks.com/topic/289332-posting-the-value-of-an-auto-submit-drop-down-list-to-another-page/#findComment-1483365 Share on other sites More sharing options...
ajoo Posted June 29, 2014 Author Share Posted June 29, 2014 Hi ! Ok so I have tried the code again as well. Just to be doubly sure that I have not made a mistake. When I select the color Red from the drop down menu, I get this error message. ( ! ) Fatal error: Cannot use isset() on the result of a function call (you can use "null !== func()" instead) in D:\xampp\htdocs\xampp\MagicOnn\testers\dropdownaction.php on line 3. Thus I do not get message "I am selected" or the value of $_POST['myselect']. Fastsol are you getting the message as well as the value of myselect? Thanks all ! Link to comment https://forums.phpfreaks.com/topic/289332-posting-the-value-of-an-auto-submit-drop-down-list-to-another-page/#findComment-1483382 Share on other sites More sharing options...
fastsol Posted June 29, 2014 Share Posted June 29, 2014 Honestly I don't know what that error means. Are you sure you changed the isset code like Ch0cu3r showed? You had to many () in your original code. This is what I have on my end that tested good. select.php <form method="post" action="dropdownaction.php"> <select name="myselect" onchange="this.form.submit();"> <option>blue</option> <option>red</option> </select> </form> dropdownaction.php <!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>Untitled 1</title> </head> <body> <?php if(isset($_POST['myselect'])) echo " I am selected".$_POST['myselect']; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/289332-posting-the-value-of-an-auto-submit-drop-down-list-to-another-page/#findComment-1483385 Share on other sites More sharing options...
Ch0cu3r Posted June 29, 2014 Share Posted June 29, 2014 @ajoo you get that error message because you have not change your if statement to the one I have posted! This is because there is an error in your code. I have highlighted what is wrong below if(isset($_POST(['myselect']))) echo " I am selected".$_POST['myselect']; // ^ ^ // | | // remove two braces, these are causing the error Link to comment https://forums.phpfreaks.com/topic/289332-posting-the-value-of-an-auto-submit-drop-down-list-to-another-page/#findComment-1483386 Share on other sites More sharing options...
ajoo Posted June 29, 2014 Author Share Posted June 29, 2014 Yes Ch0cu3r, It has worked. I don't know why I got that message. I had removed the extra parenthesis. However I have noticed that it does not work for the first value of the list. Please suggest how that can be accomplished. fastsol thanks to you too. Link to comment https://forums.phpfreaks.com/topic/289332-posting-the-value-of-an-auto-submit-drop-down-list-to-another-page/#findComment-1483388 Share on other sites More sharing options...
Ch0cu3r Posted June 29, 2014 Share Posted June 29, 2014 Either add an empty option before the first option or change the onchange event to an onblur event. Link to comment https://forums.phpfreaks.com/topic/289332-posting-the-value-of-an-auto-submit-drop-down-list-to-another-page/#findComment-1483392 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.