Fez Vrasta
Fez Vrasta

Reputation: 14835

Serialize returns empty value

Why jQuery serialize returns an empty value?

This is the HTML + JS code:
http://jsfiddle.net/nhGcq/

The code is easy, just:

alert($("#frm").serialize())

Upvotes: 1

Views: 198

Answers (4)

Denys Séguret
Denys Séguret

Reputation: 382150

Nothing is serialized because your inputs don't have a name attribute. Give them one. This name is the key in the URL type string, that's why it's necessary.

From the documentation :

For a form element's value to be included in the serialized string, the element must have a name attribute.

To automatically generate a name for your inputs, you could do something like this :

$('#frm :input').attr('name', function(num,name){
    return name||this.id||('i'+num)
});

But if you don't know the name nor id of your inputs, it might be hard to use the serialized string.

Upvotes: 1

Black Sheep
Black Sheep

Reputation: 6694

LIVE DEMO

You have to set in your <input> tag the attribute name="" to pass it.. like this:

<input type="" name="" id="" />

Upvotes: 0

charlietfl
charlietfl

Reputation: 171669

None of your inputs have a name ...only form controls with name can be serialized or submitted

Upvotes: 0

You are missing name atrribute.

That's why you are getting empty alert.

Upvotes: 0

Related Questions