Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get id's of all inputs inside the form?

How to get all id's of input elements inside a form in an array?

like image 649
James Avatar asked Jun 05 '10 17:06

James


2 Answers

Something along the lines...

<script src="../../Scripts/jquery-1.4.2.min.js"></script>

<script type="text/javascript">

    $(document).ready(function ()
    {
         // Get all the inputs into an array...
         var $inputs = $('#myForm :input');

         // An array of just the ids...
         var ids = {};

         $inputs.each(function (index)
         {
             // For debugging purposes...
             alert(index + ': ' + $(this).attr('id'));

             ids[$(this).attr('name')] = $(this).attr('id');
         });
    });


</script>
like image 67
Leniel Maccaferri Avatar answered Oct 09 '22 15:10

Leniel Maccaferri


$ids = $('#myform input[id]').map(function() {
  return this.id;
}).get();
like image 26
Amber Avatar answered Oct 09 '22 14:10

Amber