take collection and loop through it, adding attributes together as you go

Posted on 2011-10-12
Last Modified: 2012-06-21

<input name='tbca1' type='text' id='TextBoxCustomAttribs1' gatherkind='createnewuser_requiredfield' customtag='firstname' />
<input name='tbca2' type='text' id='TextBoxCustomAttribs2' gatherkind='createnewuser_requiredfield' customtag='lastname/>
<input name='tbca3' type='text' id='TextBoxCustomAttribs3' gatherkind='createnewuser_requiredfield' customtag='address1' />

What I need is to get a collection of all input tags with gatherkind*='createnewuser_requiredfield' and then loop through the collection building a custom string:


customstring += customtag + ' : ' + [[value of the input field]] + ', ';

I hope that makes sense.

I'll be working on this as well while I'm waiting.

Thank you!

Question by:knowlton
    LVL 81

    Expert Comment

    For example :

    var customstring = []; // empty new Array
    $("input[gatherkind*='createnewuser_requiredfield']").each(function() {
        customstring.push( $(this).val() );
    customstring = customstring.join(",");

    Open in new window

    LVL 11

    Assisted Solution

    leakim971 is just missing the custom attribute portion:

    var customstring = []; // empty new Array
    $("input[gatherkind*='createnewuser_requiredfield']").each(function() {
        customstring.push( $(this).attr('customtag') + ':' + $(this).val() );
    customstring = customstring.join(",");

    Open in new window

    LVL 81

    Accepted Solution

    >leakim971 is just missing the custom attribute portion:

    Ooops, my bad!

    Check this one :

    var customstring = {}; // empty new Array
    $("input[gatherkind*='createnewuser_requiredfield']").each(function() {
        customstring[$(this).attr("customtag")] = $(this).val();
    // CHECKING :
    alert( JSON.stringify(customstring) );

    Open in new window

    LVL 5

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    by Julian Matz As of jQuery ( 1.4 the .live() method ( supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
    Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
    The viewer will learn how to dynamically set the form action using jQuery.
    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…

    761 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

    12 Experts available now in Live!

    Get 1:1 Help Now