Jump to content

posting the value of an auto submit drop down list to another page


ajoo

Recommended Posts

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.

 

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 !!

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 ! 

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>

@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
                  

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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.