Jump to content

Forms and PHP: Getting Option Value into PHP


FangerZero

Recommended Posts

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.