Submiting a form using JQuery

To submit a form using JQuery use this snippet of code. This will collect all of the inputs and add them to the data and POST them to the script. Use in conjunction with Clear input fields if they are still default value.

$("#sideform").submit(function() {
var $inputs = $('#sideform :input');
var values = {};
$inputs.each(function() {
values[this.name] = $(this).val();
});

$.ajax({
type: "POST",
url: "/submit-side-form.html",
data: values,
success: function(msg){
//action to show a thank you message or hide the form
}
});
return false;
});

About Keiron

Web Developer based in the UK. Click here if you want to work with me