duanjiaolia97750 2012-01-18 10:36
浏览 57
已采纳

optgroup获取与php标签关联

I have following code in a html form

<select name="category" class="input" onchange="ShowTB(this,'suggest');">
      <option value="0" selected="selected">
        [choose yours]
      </option>
      <optgroup label="Item">
      <option value="SubItem1"SubItem1</option>
    <option value="SubItem2">SubItem2</option>
  </optgroup>
      <option value="Item2">Item2</option>
      <optgroup label="Item3">
     <option value="SubItem4"SubItem4</option>
     <option value="SubItem5">SubItem5</option>
  </optgroup>
      <option value="Item4">Item4</option>
<option value="Item5">Item5</option>
<option value="Item6">Item6</option>
<option value="Item7">Item7</option>

</select>

in php i get the value of field selected with:

$category = $_POST['category'];

in this mode if i select in the form ie: SubItem1 , in php i get value SubItem1 but i want also get associated label ie: Item or if i select SubItem5 i get SubItem5 but i want also get associated label ie: Item3 How to ?

  • 写回答

2条回答 默认 最新

  • dongzhunnai0140 2012-01-18 10:47
    关注

    Indeed, you only get the value. If you need more, just encode whatever you want into the value, for example:

    <option value="Item3.SubItem5">SubItem5</option>
    

    Alternatively, you could use javascript to catch onChange events on the select field and update a hidden input field with the desired label.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题