Solved

jquery serialize a collection of tables

Posted on 2016-09-24
3
26 Views
Last Modified: 2016-09-24
how can I get the individual tables in this each loop to display .serialize()

Screenshot:  http://www.screencast.com/t/w59pGCrThT

Currently the .serialize is blank yet the table has several inputs all with name and id

            var serializedcontent = ""
            $(target).closest('div').find('table').each(function(){
                  if($(this).attr("id"))
                  {
                        if($(this).attr("id").indexOf("BT20") > -1)
                        {
                        alert($(this).attr("id") + "~" + $('table#' + $(this).attr("id")).serialize())      
                        serializedcontent += $(this).attr("id") + "~" + $(this).serialize() + "^"
                        }
                  }
                  
            })
0
Comment
Question by:maxdbase
  • 2
3 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
do a right click on this closest div and paste here this collection of table.
0
 
LVL 21

Expert Comment

by:Kim Walker
Comment Utility
The total absence of semi-colons in your code is suspect. Is anything happening at all? Are you getting an alert? Does the alert contain the id and tilde but not the serialized id?

I am unfamiliar with the use of serialize on an attribute. The serialize function is typically executed on a form element. In fact, the documentation states
For a form element's value to be included in the serialized string, the element must have a name attribute.
But in your case, you are serializing the value of the id attribute of the target element. What do you expect the serialize function to return in this case?
0
 
LVL 21

Accepted Solution

by:
Kim Walker earned 500 total points
Comment Utility
Wait. Now I see that your are appending the value of the id attribute to the string table#. I believe you are intending to target the element with the target id that is a descendant of any table. If that is the case, you need to insert a space between table and #.
$('table #' + $(this).attr("id")).serialize()

Open in new window

However, since id values are required to be unique, the table ancestor selector is unnecessary.
$('#' + $(this).attr("id")).serialize()

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now