Home > DeveloperSection > Forums > Array of html input type=“button” in jquery?
David Miller

Total Post:30

Points:210
Posted on    November-03-2014 5:33 AM

 ASP.Net JQuery  Array 
Ratings:


 1 Reply(s)
 754  View(s)
Rate this:

I have 3 Html input button in my web page.

<input id="Meal0" runat="server" type="button" class="btn-free arrayinput" />

<input id="Meal1" runat="server" type="button" class="btn-busy arrayinput" />

<input id="Meal2" runat="server" type="button" class="btn-primary arrayinput" />

now I want to have an array of 3 elements in my jquery function:

here is my all code:

 

        $("#btnNextWeek").click(function (e) {

            var MealsButton = $('.arrayinput');

            var Meals = s.split('!~!');

            for (var i = 0; i <= 2; i++) {

 

                MealsButton[i].css("color", "black");

                MealsButton[i].css("width", "200px");

                MealsButton[i].css("height", "60px");

 

                if (Attr[1] == "1") {

                    MealsButton[i].css("class", "btn-app btn-success btn arrayinput");

                    MealsButton[i].css("Buy", Attr[4] + ":" + Attr[3]);

                    MealsButton[i].val("خرید ژتون");

                }

 

                else if (Attr[2] == "1" && Attr[5] != "empty chip") {

                    MealsButton[i].css("class", "btn-app btn-free btn arrayinput");

                    MealsButton[i].css("DelBtn", Attr[5]);

                    if (Attr[6] != "empty chip") {

                        if (Attr[6] != "empty chip") {

                            MealsButton[i].val(Attr[6]);

 

                        }

 

                        else {

                            MealsButton[i].css("class", "btn-app btn-disable btn arrayinput");

 

                            if (Attr[6] != "empty chip") {

                                MealsButton[i].val(Attr[6]);

                            }

                            else {

                                MealsButton[i].val("");

                            }

                        }

                    }

 

                }

 

            }

        });

this error ocured :

0x800a01b6 - Microsoft JScript runtime error: Object doesn't support this property or method

how can i have an array of my html input elements and how can access to my array elements ?



sandy taylor
sandy taylor

Total Post:46

Points:324
Posted on    November-03-2014 6:50 AM

Let me make a suggestion.

Give a custom class to the inputs

           <input id="Meal0" runat="server" class="arrayinput" type="button" />
            <input id="Meal1" runat="server" class="arrayinput" type="button" />
            <input id="Meal2" runat="server" class="arrayinput" type="button" />

And Script can go like

  $("#btnNextWeek").click(function (e) {

var MealsButton = $('.arrayinput');

} });

Meals button will be the array of inputs as you want it.

You can use MealsButton variable to add any properties since it is equivalent to the selector.

For example

MealsButton.css('width','200px');

If you want to access each element separately. Then

MealsButton.each(function (index, value) {

           $(this).css('width','200px');

});

Don't want to miss updates? Please click the below button!

Follow MindStick