Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

drop down menu - PHP get dropdownlist select option value

In my dropdownlist I have two different values for each option. How can I retrieve both? Let me illustrate what I mean.

<select name="my_ddl">
  <option value="<?php $value_Id ?>"><?php $value_text ?></option>
  <option value="<?php $value_Id ?>"><?php $value_text ?></option>
</select>

When the form is posted, I want to be able to get both the $value_id and $value_text of the selected option. How can I do this?

$_POST['my_ddl'] only gets one value not both.

In asp.net I could do this simply by referring to my_ddl.Value and my_ddl.Text.

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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']);
   //...
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...