通过ajax onchange事件传递选定的值
Pass a selected value through ajax onchange event
我有一个选择表单:
<form id="form" name="nameForm">
<select id="selectId" onchange="loadAjax('url.php');return false;">
<option>One</option
<option>Two</option>
</select>
</form>
我希望当用户更改所选选项时,它会加载带有url中值的ajax函数(通过GET)。
所以我尝试了几种方法,这是我最后一次尝试:
onchange="
var e = document.getElementById('form');
var strSel = e.form.selectId.value;
loadAjax('url.php?v='+strSel);
return false;
">
不是很正确。有人知道如何正确地做到这一点吗?
您在options
中缺少值属性
我试过了,它在添加值后有效,比如
<select id="selectId" onchange="alert('url.php?v='+this.value);return false;">
<option value="one">One</option>
<option value="two">Two</option>
</select>
你应该试试这个,
<select id="selectId" onchange="loadAjax('url.php?v='+this.value);return false;">
<option value="one">One</option>
<option value="two">Two</option>
</select>
工作Fiddle
根据您的代码示例,这将适用于
onchange="
var e = document.getElementById('selectId');
var strSel = e.options[e.selectedIndex].value;
loadAjax('url.php?v='+strSel);
return false;
">
相关文章:
- ajax互联网浏览器onchange
- HTML onchange未从Ajax插入中激发
- ajax表单每触发第n个select onchange事件就发送n次
- Ajax;选中3个项目后,JavaScript多选onchange失败
- 如何在 ajax 上添加 onchange 事件
- PHP 填充下拉列表与 ajax onchange 问题 IE 仅限
- 使用AJAX和PHP进行Onchange选择
- jQuery.ajax post从select标记返回从onchange事件调用的页面的整个html
- onchange ajax调用的dropdownlistMVC重载问题
- 使用数据库onchange中提供的ajax值进行自动计算
- 在粘贴responseText后,调用Ajax响应文本中存在的Javascript onchange函数
- Onchange使用ajax在表行中追加数据
- 在onChange事件上将Form元素值传递给Ajax Post方法
- 无法更改ajax成功返回时的image-onChange函数
- f:ajax by onchange event
- PHP 使用 onchange 将文件上传到 Ajax
- 通过ajax onchange事件传递选定的值
- Javascript / Ajax -动态添加行的onchange事件
- Ajax onchange禁用第二个Ajax调用onclick
- Jquery onchange Ajax