rockinaway Posted August 8, 2011 Share Posted August 8, 2011 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 More sharing options...
the182guy Posted August 8, 2011 Share Posted August 8, 2011 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 https://forums.phpfreaks.com/topic/244209-access-to-a-dropdown-name/#findComment-1254214 Share on other sites More sharing options...
AyKay47 Posted August 8, 2011 Share Posted August 8, 2011 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 https://forums.phpfreaks.com/topic/244209-access-to-a-dropdown-name/#findComment-1254220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.