Reputation: 423
I am using a cakephp form. I have a dropdown select box. If dropdown value changes then the form should submit.Is there any method similar to form submission like this.form.submit for ajax forms. Any help?
Upvotes: 1
Views: 376
Reputation: 38342
If jquery is okay for you you can do
$('#myDropdown').change(function() {
$(this).closest('form').submit();
});
if you want ajax replace line 2 as follows
var myForm = $(this).closest('form');
$.post(myForm.attr('action'), myForm.serialize(), function(data)
{
/*do something on success*/
}
Upvotes: 1
Reputation: 6910
You can use dropdown elemnts onChange event
$('.target').change(function() {
alert('Handler for .change() called.');
});
Upvotes: 0
Reputation: 1038710
If you use jQuery you could use the .serialize()
method and AJAXify a form like this:
$(function() {
$('#myform').submit(function() {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function(result) {
// TODO: process the results
}
});
return false;
});
});
Another possibility is to use the excellent jQuery form plugin.
Upvotes: 0