doudiewen9435 2015-12-27 09:24
浏览 19

从msdropdown下拉框中捕获值

In the above code I am trying to capture the value of idnum in the variable $image_result to no avail. Any help would be greatly appreciated

echo "<select name='myitem' id='myitem' action='post>";

while($row = mysql_fetch_array($result1)){
  echo "<option value='".$row["idnum"]."' data-image='/components/com_aclsfgpl/photos/p".$row["idnum"]."n1.jpg'>".$row["title"]."</option>";
}

echo "<option value='". $row['idnum']."'>".$row['title']. '</option>';
echo "</select>";
$image_result=$_POST['myitem'];
  • 写回答

1条回答 默认 最新

  • dongyied24121 2015-12-27 09:50
    关注

    A basic example of how you can capture the values from the dropdown, including the data attributes. The original was not valid - the select element does not have an action attribute - that belongs to the form - of which there is no sign. If you were to use this method it is trivial to then POST this data to another script/page as required or work withit in the same page with javascript.

    <select name='myitem' onchange='getvalue(this)'>
        <option value='1' data-image='1'>Option 1
        <option value='2' data-image='2'>Option 2
        <option value='3' data-image='3'>Option 3
    </select>
    
    <script>
        function getvalue( n ){
            var oItem=n.options[ n.options.selectedIndex ];
            alert( oItem.value +' '+oItem.dataset.image+' '+oItem.text );
        }
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)