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

Link to comment
Share on other sites

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>

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.