0
$('#mybutton').click(function(){
var form = $(this).parents('form:first');
var values = form.serialize();

//do some ajax calls
})

Now I want to do something like this

$("#myForm :input[value]").serialize() on the parent form

but I cant find a way to do this.I am guessing I have to use .find()

3

3 Answers 3

4

Not sure I get this, but the context selector is a shortcut for find(), and this.form should be the parent form ?

$(":input[value!='']", this.form).serialize()
Sign up to request clarification or add additional context in comments.

Comments

1

You would do

var values = $(this).parents('form:first').find(":input[value][value!='']").serialize();

or in your second case,

var values = $("#myForm :input[value][value!='']").serialize();

See related question for more details.

1 Comment

I am trying to do the first one but my values string contains only a radio button value
0

I dont know what the problem is but

$(":input[value!='']", this.form).serialize()

is not working for me and I am not sure what it does as it seems to filter only default values I spent too much time to get that to work and ended up manually filtering the inputs

var data={};
var formData = form.serializeArray();
$.each(formData, function (index, value) {
    var data_name = formData[index].name;
    var data_value = formData[index].value;
    if (data_value !== "") {
        data[data_name] = data_value;
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.