Excluding certain inputs on serialize

I am not happy with 'input[name!=security]' because it exclude all other input type like select,.. You can add them manually but this list just keep increasing with new HTML tags. So with every new tag coming, your code is broken again.

Here is my solution:

$form.find(':not(input[name=draft])').serialize()

or

$('form[name=expenses] :not(input[name=draft])').serialize()

Space is very important in second example.


First, you need to invoke the .find() method like:

var serializedReturn = $(this).find('input[name!=security]').serialize(); 

Otherwise the complete string would go into the css query engine (Sizzle).

Secondly:

I have another form with the id of ofform-reset and if i use:

You need to change this. It's invalid markup to have multiple ID's. If I understood you wrong here, the first solution might also help you here, invoking the .find() method aswell:

var serializedReturn = $('#ofform').find('input[name!=security]').serialize(); 

You don't need the :, because input is an element not a pseudo selector. Secondly you cannot use an object and a text string like that in your selector. You instead need to supply this as the scope argument to $():

$('#ofform').live('submit', function(e) {
    e.preventDefault();
    var serializedReturn = $('input[name!=security]', this).serialize();        
});