In my dropdownlist I have two different values for each option. How can I retrieve both? Let me illustrate what I mean.
If you're using PHP to populate the text for the <option>
then you can probably just look the value up on the server. Perhaps you just need to use the $value_id to look up the text in a database table?
If not, you could include a hidden field on your form and use JavaScript to update that hidden field with the text every time a new value is selected.
Another strange way of doing it is:
<select name="my_ddl">
<option value="<?php echo $value_Id ?>[<?php echo $value_text ?>]">
<?php echo $value_text ?>
</option>
</select>
Then when you process it you can do this or maybe even something more simple:
foreach ($_POST['my_dd1'] as $value_Id => $value_text) {
$value_Id = $value_Id;
$value_text = $value_text;
}
Because php treats the [] as meaning the string is an array and so you instantly have an associative array. I agree though that if you put it there in the first place you ought to be able to just look it up again in the code rather than rely on this.
You cannot get value_text from POST data. One solution is to populate the hidden field after choosing the option via JavaScript.
Strictly, this is not possible.
What you could do is use a delimiter in your value
attribute:
<select name="my_ddl">
<option value="<?php echo $value_Id ?>|<?php echo $value_text ?>"><?php echo $value_text ?>
</option>
</select>
And...
<?php
list($id, $text) = explode('|', $_POST['my_ddl']);
//...
?>