Monday, June 1, 2009

[jQuery] How to prevent a particular field being submitted in form submission

I have email, password and some other fields, and I'm using $.post to
send data.

$("#MyForm").submit(function(){
$.post('/register.php',
$(this).serializeArray(),
callback,
"json"
);
return false;
});


In Ajax form submission, I don't want to submit a particular field.
The serializeArray() method returns all the fields in the form. So, I
tried something like this to prevent the password field being
serialized.

var serialized = [];
$(this).serializeArray().filter(function (value, index) {
if (value.name != "data[User][passwd]") {
serialized.push(value);
}
});

This works great but the ajax submission doen't work.
Is there any solution for this?
Many thanks!

No comments: