dongsong1911 2013-06-24 08:04
浏览 77
已采纳

通过ajax onchange事件传递选定的值

I have a select form:

<form id="form" name="nameForm">

<select id="selectId" onchange="loadAjax('url.php');return false;">
<option>One</option
<option>Two</option>
</select>

</form>

I want that when the user changes the selected option, it loads the ajax function with the value in the url (trough GET).

So I tried several things and this was my last try:

onchange="
var e = document.getElementById('form');
var strSel = e.form.selectId.value;
loadAjax('url.php?v='+strSel);
return false; 
">

Not really correct. Does someone know how to do this correctly ?

  • 写回答

2条回答 默认 最新

  • duanfu2562 2013-06-24 08:12
    关注

    You are missing value attribute in options

    I tried it and it works after adding value, like,

    <select id="selectId" onchange="alert('url.php?v='+this.value);return false;">
       <option value="one">One</option>
       <option value="two">Two</option>
    </select>
    

    You should try this,

    <select id="selectId" onchange="loadAjax('url.php?v='+this.value);return false;">
       <option value="one">One</option>
       <option value="two">Two</option>
    </select>
    

    Working Fiddle

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

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源