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 selected
option that is posted). You can use javascript to alter a hidden input
field with the text contents of a selected option
, and this will be included in the $_POST
array:
<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.
code
more code
~~~~