tags:

views:

990

answers:

1

Hello,

I need to loop through a set of 2-dimensional array of hidden input fields and display matching values next to each other.

Example of hidden fields:

       <input type="hidden" name="list[en][1]" class="list" value="Keyword">
       <input type="hidden" name="list_desc[en][1]" class="listdesc" value="Keyword description">

       <input type="hidden" name="list[en][2]" class="list" value="Keyword2">
       <input type="hidden" name="list_desc[en][2]" class="listdesc" value="Keyword description 2">
...

And the output values here :

$(".list").each(function(){ $("p").text('list[1] = ' + $list + 'description[1] = '+ $description);
});
A: 

Given your example I would consider their relative DOM placement and not worry about matching them up by name.

$('.list').each( function(i) {
    var j = i + 1;
    $('p').text('list[' + j + '] = ' + $(this).attr('value')
                + ' description[' + j + '] = '
                + $(this).next('input[type=hidden]').attr('value') )
          .appendTo( '#someSelector' );
});
tvanfosson