Reputation: 1163
i wanted to pass the text of the option selected in a selectbox through traditional form submit and get it on other page
normally we get the value of selected option from selectbox using $degree=$_REQUEST['example'];
<select name="example">
<option value="1">example</option>
</select>
What we normally get is value that is if we echo $degree would be 1
. I want the text that is example
Upvotes: 0
Views: 110
Reputation: 5428
as @Andy previously mentioned:
you can use a delimiter like below if you need both values :
<select name="example">
<option value="1_example">example</option>
</select>
in your php you do like below :
$temp = explode('_', $_REQUEST['example']);
echo $temp[0] ; // will output '1'
echo $temp[1]; // will output 'example'
Upvotes: 1
Reputation: 8908
This is a function of HTML in the browser, not PHP. You can either use JavaScript to scrape out the text inside the option tag, or just put the string inside the value and use string parsing with some separator in PHP to get it out as such:
<option value="1:::example">example</option>
If you truly only care about the text and not at all about the number, just replace the number with the text:
<option value="example">example</option>
Upvotes: 4