Reputation: 14835
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
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
Reputation: 6694
You have to set in your <input>
tag the attribute name=""
to pass it.. like this:
<input type="" name="" id="" />
Upvotes: 0
Reputation: 171669
None of your inputs have a name
...only form controls with name
can be serialized or submitted
Upvotes: 0
Reputation: 57095
You are missing name atrribute
.
That's why you are getting empty alert.
Upvotes: 0