Reputation:
I tried to use a jquery object to serialize some of values in a form. I tried using a div id that surrounded the fields I needed like this:
var test = $("#div_tab1").serialize()
and it was empty
var test = $("#form1").serialize() worked.
shouldn't the first example work?
I am using version 1.6.4
Upvotes: 2
Views: 449
Reputation: 180
In case you do not want to serialize the whole form, you can serialize elements within a specific #id or even a specific element name.
// serialize input elements within a specific #id
$('#id :input').serialize();
// serialize a specific element in the form
$('input[name=inputName]').serialize();
Upvotes: 0
Reputation: 9508
I’ve found that serialize works on a form or a jQuery of :input tags, but not a div that contains :input tags.
Upvotes: 0
Reputation: 298176
From the API:
.serialize()
:Description: Encode a set of form elements as a string for submission.
Notice how it says form elements
.serialize()
returns a string that is meant to be placed in URLs: ?bar=baz&foo2=bar
.
It won't make sense for a non-form element, as it doesn't have a value
attribute.
Upvotes: 0
Reputation:
"shouldn't the first example work?"
No, you need to call it on a form, or on a set of input elements.
Upvotes: 2