最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to click the save button in form automatically using jquery - Stack Overflow

programmeradmin3浏览0评论

I have an form with dropdown. whenever i select the drop down once i click save itself it appear it do some action. I want to as auto save when you change the dropdown values. Here is the fiddle: /

jQuery('select[name="dropdown"]').change(function() { 
alert(jQuery(this).val());
});
jQuery('#submit').click(function() {
    alert('you click submit button');
});

I want once you select the dropdown it automatically submit the values means it automatically click save without noticing to the user.

Any suggestion would be great.

Thanks

I have an form with dropdown. whenever i select the drop down once i click save itself it appear it do some action. I want to as auto save when you change the dropdown values. Here is the fiddle: http://jsfiddle/GGtTw/

jQuery('select[name="dropdown"]').change(function() { 
alert(jQuery(this).val());
});
jQuery('#submit').click(function() {
    alert('you click submit button');
});

I want once you select the dropdown it automatically submit the values means it automatically click save without noticing to the user.

Any suggestion would be great.

Thanks

Share Improve this question asked Sep 30, 2013 at 14:15 Vignesh PichamaniVignesh Pichamani 8,07022 gold badges80 silver badges117 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

Use trigger to simulate a click event for the given object

jQuery('select[name="dropdown"]').change(function() { 
    jQuery('#submit').trigger('click');
});
jQuery('#submit').click(function() {
    alert('you click submit button');
});

just do

$( "#submit" ).trigger( "click" );

Another Approach:

jQuery('select[name="dropdown"]').change(function() { 
    save();
});
jQuery('#submit').click(function() {
    save();
});
function save()
{
alert('Save');
}

Make an ajax call to save from inside your drop down change event. Unless you want to perform a form submit, in that case trigger the click function on the submit like so

jQuery('#submit').trigger('click');

jQuery ajax()

发布评论

评论列表(0)

  1. 暂无评论