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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度