0

here is my code :

$('#CheckBoxList1').change(function () {
                var CHK = document.getElementById("<%=CheckBoxList1.ClientID%>");
                var checkbox = CHK.getElementsByTagName("input");
                if ($.browser.msie) {
                    for (var i = 1; i < checkbox.length; i++) {
                        if (checkbox[i].checked) {
                            markers[i - 1].setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png');
                        }
                        else {
                            markers[i - 1].setIcon('http://maps.google.com/mapfiles/ms/icons/red-dot.png');
                        }

                    }
                }
          });

        });

in for loop I'm finding checked checkboxes from checkboxlist1.I'm setting marker colors which names are checked in chekboxlist.İt's working succesfull with for loop. But I will making this process when I checked a checkbox.I don't will using a for loop to finding all checked checkboxes.So I will do, when I checked a checkbox on chekboxlist I will getting thet checkbox's Index(sequence number) number.When I get that index number I musn't using a for loop and I can working on markers with that index number. İ.E I have a checkbox list i.e it haves 5 checkboxes tahats texes are a,b,c,d,e . For example: when I cheked 'e' checkbox I will getting that checkbox index number which is 5,when I cheked 'c' checkbox I will getting that checkbox index number which is 3

Ebrar Bayburt
  • 37
  • 1
  • 3
  • 9

1 Answers1

1

Just use the index() function. And please be aware that some IE browsers may not recognize the .change() event, rather use .propertychange as shown here

Also, what's the point of using jQuery when you still select your elements using document.getElementById?

$(function() {
    $('#CheckBoxList1 input').change(function() {
        var index = $('#CheckBoxList1 input').index(this);
    });
});
Community
  • 1
  • 1
Alex
  • 9,911
  • 5
  • 33
  • 52
  • well, $(function() {...}); is a short form for $(document).ready(function() {...});. where you use the function itself depends on when you need it – Alex Feb 25 '13 at 10:48
  • I writed under the var index=... line a alert(); if I checked 1 box it displays once,if I chacked 2 box it displays twice,when 3 display 3... there is not a loop. why it displays so – Ebrar Bayburt Feb 25 '13 at 11:06
  • dude I have no idea what you mean. Please set up your markup at jsfiddle.com and demonstrate what you mean – Alex Feb 25 '13 at 11:10