Jump to content

Access to a dropdown name


rockinaway

Recommended Posts

I know you can use $_POST['dropdown_name'] to get access to which value is chosen in a dropdown menu. However if I have:

 

<select name="info">
						<option value="user">This is a user</option></select>

 

Usually, if I use $_POST['info'] I would get the value 'user'. However is there any way to get the actual text that is used to describe the selected option? i.e. the 'This is a user' part?

 

 

Link to comment
https://forums.phpfreaks.com/topic/244209-access-to-a-dropdown-name/
Share on other sites

That part is not sent to the server so you would need to add it to the value with a delimeter for example:

 

<option value="user:This is a user">This is a user</option></select>

 

Then in your PHP when it's submitted, parse the value with something like explode() to get both pieces.

 

Another option is to use Javascript to send the display text to the server as well.

in your case, you would typically set the option value to the same text that is displayed to the user...most likely using a variable..

 

<select name="info">							
<option value="<?php print $user; ?>"><?php print $user; ?></option></select>

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.