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: http://jsfiddle.net/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

4 Answers 4

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');
});
Sign up to request clarification or add additional context in comments.

Comments

2

just do

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

Comments

1

Another Approach:

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

Comments

1

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()

2 Comments

Technically correct, but strikes me as an unnecessarily large amount of work for such a trivial problem.
Anthony, typically on a drop down select, there is no need for a post back, so an ajax save call is usually what people do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.