Good day. Trying to perform such a moment. I need to write in the array the value of value and name at INPUT. The design should be like this.

var mas = ("black" => "Black", "brown" => "Brown", "white" => "White").

Here is a div with input.

<div class="bl_choiceOfColor"> <input class="active" type="submit" value="Черный" name="black" status="opend"> <input type="submit" value="Бурый" name="brown" status="closed"> <input type="submit" value="Белый" name="white" status="closed"> <div class="clear"></div> </div> 

Here is the script that I am writing.

 var COLOR_prod = []; $(".bl_choiceOfColor input").each(function(i){ var that = $(this); if(that.hasClass("active")){ COLOR_prod[i] = that.attr("name"); } }); 

Values ​​are written only as to write values ​​/

    2 answers 2

    do not use an array, but a regular hash:

     var COLOR_prod = {}; $('.bl_choiceOfColor').find('input').each(function(){ var that = $(this); if(that.hasClass("active")){ // var mas = ("black" => "Черный","brown" => "Бурый","white" => "Белый" ). COLOR_prod[this.name] = this.value; } }); 

      In general, @Spectre has already answered everything, but as an alternative:

       var COLOR_prod = {}; $('.bl_choiceOfColor .active').map(function(){ return COLOR_prod[$(this).attr('name')] = $(this).val(); }); console.log(COLOR_prod);