This is not something that can be done through PHP alone. The PHP script can only “see” the information which is posted (the
value for the
input field with the text contents of a selected
option, and this will be included in the
<form action="test.php" method="POST"> <select id="test" onchange="document.getElementById('text_content').value=this.options[this.selectedIndex].text"> <option value="1">Test One</option> <option value="2">Test Two</option> </select> <input type="hidden" name="test_text" id="text_content" value="" /> </form>
This will make the
$_POST['test_text'] available with the selected index (but you should also force the onchange() function when the page loads so that it will be populated even if the user leaves the select field at the default value.