SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery - capturing a dynamically generated set of input data

    I've got a form that dynamically generates sets of input elements. First there is a set of up to 99 parent elements, and then the parents can have up to 99 child elements each. My question is not about the generation, but about capturing the data once the form has been filled out.

    I made a script that handles getting the values and putting the values, along with their input id in an object that is used later. I don't want to have to use css classes or other attributes to identify the input elements, and wondering if that being the case, if I could get a critique of my script:

    Edit this Fiddle - jsFiddle - Online Editor for the Web (JavaScript, MooTools, jQuery, Prototype, YUI, Glow and Dojo, HTML, CSS)

    The output (the object) logs to your console when you click anywhere in the Result area.

  2. #2
    SitePoint Enthusiast Anthony.Barnes's Avatar
    Join Date
    Aug 2011
    Location
    Canberra, Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by 'capturing'? If it is to post back to the server you can just use the jQuery .serialize() function to get all the form elements and their values into a post body.

    I can see in your example that you are combining the ids into an object, but perhaps you want it structured?

    Edit this Fiddle - jsFiddle - Online Editor for the Web (JavaScript, MooTools, jQuery, Prototype, YUI, Glow and Dojo, HTML, CSS)

  3. #3
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Anthony.Barnes View Post
    What do you mean by 'capturing'? If it is to post back to the server you can just use the jQuery .serialize() function to get all the form elements and their values into a post body.

    I can see in your example that you are combining the ids into an object, but perhaps you want it structured?

    Edit this Fiddle - jsFiddle - Online Editor for the Web (JavaScript, MooTools, jQuery, Prototype, YUI, Glow and Dojo, HTML, CSS)
    Yes, I know I could use serialize, but by capturing I just meant that I want to put all of the values from the fields in an object. The form is very large, and parts of it show and parts are hidden, making it seem as though there are pages. $.serialize would work if I want to GET or POST the entire form, but only one part is done at a time. You are probably wondering why I haven't just made separate forms for each page... and I think I am wondering the same thing right now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •