Timunit Posted October 21, 2008 Share Posted October 21, 2008 Hi, I am trying to query my database based on a drop down list and I am having trouble getting it to work. So I wrote some code to experiment with capturing the value of a drop down list but I am having trouble with that as well. I know I am missing something obvious but I am sort of a PHP newbie. Here is the code: echo "<form name='choosetrip' method='POST'><select name='trip'>"; echo "<option value='%'>Select a Trip</option>"; echo "<option value='2'>April 2008</option>"; echo "<option value='3'>April 2009</option>"; echo "</select>"; echo "</form><br>"; $trip = $_POST["trip"]; echo $trip; if(isset($trip)) { echo "YES"; } else { echo "NO"; } This is simply a drop down with three choices. I want the code to echo the value that is chosen and echo Yes or No whether the value has been set. But when I change the drop down nothing happens: no value shows and the answer remains No. For some reason the value of the drop is not being sent. Any suggestions? Thanks, Tim Link to comment https://forums.phpfreaks.com/topic/129405-working-with-drop-down-list/ Share on other sites More sharing options...
revraz Posted October 21, 2008 Share Posted October 21, 2008 It's not being sent because you never leave the page to "submit" the values. If you want to do this dynamicaly, on the same page, you need to use Javascript or AJAX. There is a example in the FAQ forums. Link to comment https://forums.phpfreaks.com/topic/129405-working-with-drop-down-list/#findComment-670898 Share on other sites More sharing options...
Timunit Posted October 21, 2008 Author Share Posted October 21, 2008 revraz, Thank you. I knew it was something simple. As I said, I am a newbie. I added a submit button and now it works. I will look into to using Javascript to make it more dynamic. Thanks for your help. Tim Link to comment https://forums.phpfreaks.com/topic/129405-working-with-drop-down-list/#findComment-671284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.