FangerZero Posted October 31, 2009 Share Posted October 31, 2009 OK how do I get the VALUE, not the text, into PHP as a variable after pushing a button? What I'm doing is, I have two Pages. a Main Menu page; where you can select which option you want. Then a viewing page; to view anything attached to the data that was selected. You go from Main Menu to viewing page via button. And I know to get the selected text so if I chose Dogs, I would know how to get that printed out on View, but I need the '1' from Value. <form name="MainMenu" method="POST" action=View.php> <input type="submit" name="View" value="View"> <select name=Animal size=5> <option value=1>Dogs</option> <option value=2>Cats</option> <option value=3>Fish</option> <option value=4>Birds</option> </select></form> Quote Link to comment https://forums.phpfreaks.com/topic/179762-forms-and-php-getting-option-value-into-php/ Share on other sites More sharing options...
sKunKbad Posted October 31, 2009 Share Posted October 31, 2009 On View.php <?php echo $_POST['Animal']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/179762-forms-and-php-getting-option-value-into-php/#findComment-948488 Share on other sites More sharing options...
FangerZero Posted November 1, 2009 Author Share Posted November 1, 2009 again I want the VALUE I will not get the number 1 that I need, but Dogs. Please read post and ask questions before giving an obvious answer. Quote Link to comment https://forums.phpfreaks.com/topic/179762-forms-and-php-getting-option-value-into-php/#findComment-948524 Share on other sites More sharing options...
Alex Posted November 1, 2009 Share Posted November 1, 2009 You're asking for the value, he gave you the way to get the value. You're asking the question wrong, so expect a wrong answer. Simply put, you can't do what you want. Why don't you just make the value "Dogs" if that's what you want? Quote Link to comment https://forums.phpfreaks.com/topic/179762-forms-and-php-getting-option-value-into-php/#findComment-948525 Share on other sites More sharing options...
sKunKbad Posted November 1, 2009 Share Posted November 1, 2009 Yes, what he said.... You need to change your value="1" to value="dogs". Either that, or use a switch to reference what number belongs to what animal, or use foreach on an array that compares the value to a key. Quote Link to comment https://forums.phpfreaks.com/topic/179762-forms-and-php-getting-option-value-into-php/#findComment-948532 Share on other sites More sharing options...
3raser Posted November 1, 2009 Share Posted November 1, 2009 Did you do <?php $example = $_POST['animal']; echo $example; ?> Quote Link to comment https://forums.phpfreaks.com/topic/179762-forms-and-php-getting-option-value-into-php/#findComment-948537 Share on other sites More sharing options...
HaLo2FrEeEk Posted November 1, 2009 Share Posted November 1, 2009 Also you shouldn't rely on just names as identifiers in input and select objects. use name="" and id="" at the same time, and make sure they're both the same. Also, why is your select size=5 if there's only 4 options? And finally, use quotes. Different browsers handle code differently, using proper code standards helps eliminate cross-browser issues. Quote Link to comment https://forums.phpfreaks.com/topic/179762-forms-and-php-getting-option-value-into-php/#findComment-948546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.