admin管理员组文章数量:1429552
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 ?
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 ?
Share Improve this question edited Jun 24, 2013 at 8:15 abhinav 1,2821 gold badge10 silver badges27 bronze badges asked Jun 24, 2013 at 8:04 Nicolas.Nicolas. 4531 gold badge7 silver badges27 bronze badges 2-
3
take a look at
jquery
your life will be much easier. – DevZer0 Commented Jun 24, 2013 at 8:07 - thanks but I'm not using Jquery – Nicolas. Commented Jun 24, 2013 at 8:13
2 Answers
Reset to default 2You 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
According to your code sample this will work
onchange="
var e = document.getElementById('selectId');
var strSel = e.options[e.selectedIndex].value;
loadAjax('url.php?v='+strSel);
return false;
">
本文标签: phpPass a selected value through ajax onchange eventStack Overflow
版权声明:本文标题:php - Pass a selected value through ajax onchange event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745480138a2660137.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论