admin管理员组文章数量:1291038
This is my code: /
It should submit the form on select change but it doesnt do anything
$(function() {
$('#candidate_filter').change(function() {
this.form.submit();
});
});
Can anyone please explain why this code doesn't work?
This is my code: http://jsfiddle/47apf/
It should submit the form on select change but it doesnt do anything
$(function() {
$('#candidate_filter').change(function() {
this.form.submit();
});
});
Can anyone please explain why this code doesn't work?
Share Improve this question asked Jul 9, 2014 at 11:10 J.ZilJ.Zil 2,4498 gold badges46 silver badges82 bronze badges 1- 1 this is already the form. try this.submit(); – Hank Lapidez Commented Jul 9, 2014 at 11:14
7 Answers
Reset to default 5Well, you don't need the .form
in this case.
$(function() {
$('#candidate_filter').change(function() {
this.submit();
});
});
Here, this
itself is the form.
Write this:
$('#candidate_filter').change(function() {
$(this).trigger('submit');
});
Updated fiddle here.
Try this
$('#candidate_filter').change(function() {
//alert("hii");
this.submit();
});
Fiddle: fiddle
You need to assign id of drop down as below:
<form id="candidate_filter">
<select name="vacancy" id="candidate_filter1">
<option value="all">Any Vacancy</option>
<option value="1">Engineering lk;lk;</option>
</select>
<select name="status" id="candidate_filter2">
<option value="all">Any Status</option>
<option value="open">Open for applications</option>
<option value="closed">Closed for applications</option>
<option value="inactive">Inactive</option>
</select>
<select name="date">
<option value="all">Any Date</option>
<option value="today">Today</option>
<option value="3">3 days</option>
<option value="7">This week</option>
</select>
<select name="consideration" id="candidate_filter3">
<option value="all">Any Consideration</option>
<option value="qualified">Qualified</option>
<option value="rejected">Rejected</option>
</select>
<input type="submit">
</form>
JS
$(function() {
$('select[id^="candidate_filter"]').change(function() {
this.form.submit();
});
});
DEMO
You have to submit the form like this: $('#candidate_filter').submit();
Here is a working JSFiddle: http://jsfiddle/47apf/5/
JQuery
$(function() {
$('#candidate_filter').change(function() {
alert("change event catched");
$('#candidate_filter').submit();
});
});
You can do like this in jQuery.
Put a class on your select, and bind the event onchange
$('.candidateList').on('change', function(evt){
$('#candidate_filter').submit();
});
http://jsfiddle/darksioul/4ygAg/2/
Try:
$(function() {
$('#candidate_filter select[name="vacancy"]').change(function() {
$('#candidate_filter').submit();
});
});
Inside jQuery selectors, the this word references to the selected element on DOM, in you original code, $('#candidate_filter') represents the FORM element. Adding a second reference you have a better approach to what you desire $('#candidate_filter select[name="vacancy"]'). And to submit the form, you need to point especifically to the FORM element.
本文标签: javascriptSubmit form on select changeStack Overflow
版权声明:本文标题:javascript - Submit form on select change - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741520880a2383175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论