doufen3134 2018-09-24 19:08
浏览 44

将所选名称POST到数据库

I have a combobox which is populated from my database:

<select id="product" name="product">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

I am using the form method post to send the selected value to my database:

$product = $_POST['product'] ;

When I send the data to my database I only get the selected value in my database ('1', '2' or '3').

I also want to send the name of the selected option to my database ('One', 'Two' or 'Three').

Does someone know if it is possible to post the name of the selected value to the database?

  • 写回答

5条回答 默认 最新

  • doubei8541 2018-09-24 19:15
    关注

    You could use a hidden field, and update that field, on option change with JavaScript.

    <input type="hidden" name="numberWritten" id="numberWritten" value="" />
    

    JavaScript:

    document.getElementById('product').onchange = function() {
        var element = document.getElementById('product');
        var otherValueFromOption = element[element.selectedIndex].innerHTML;
        document.getElementById('numberWritten').value = otherValueFromOption;
    }
    

    You now have a $_POST['numberWritten']. With a value of either One Two or Three

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?