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;
">