Abhimanyu
Abhimanyu

Reputation: 423

ajax form submission

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

Answers (3)

aWebDeveloper
aWebDeveloper

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

nidhin
nidhin

Reputation: 6910

You can use dropdown elemnts onChange event

Example

$('.target').change(function() {
  alert('Handler for .change() called.');
});

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

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

Related Questions