Monday, April 27, 2015

asp.net textbox limit characters

   var MaxLength = 7;
            $('#<%=txtZip.ClientID%>').keypress(function (e) {
                alert('textbox -' + $(this).val().length);
                if ($(this).val().length > MaxLength) {
                    alert('true');
                    e.preventDefault();
                }
            });

Thursday, April 23, 2015

JavaScript Array pop() Method

<!DOCTYPE html>
<html>
<body>

<p>Click the button to remove the last element from the array.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits;

function myFunction() {
    fruits.pop();
    document.getElementById("demo").innerHTML = fruits;
}
</script>

</body>
</html>

ASP.NET CheckBoxList Operations with jQuery - change color on checkbox click

 $("#<%= chk.ClientID %> :checkbox").click(function () {

                $(this).parent().css('color', $(this).is(':checked') ? 'blue' : 'black');
       
            });

ASP.NET CheckBoxList Operations with jQuery - change color of checked items

 $("[id*=chk] input:checked").each(function () {

                            $(this).parent().css('color', $(this).is(':checked') ? 'blue' : 'black');

                       

                        });

ASP.NET CheckBoxList Operations with jQuery - Max Selection Limit

$("[id*=CheckBoxList1] input:checkbox").change(function () {
          var maxSelection = 3;
          if ($("[id*=CheckBoxList1] input:checkbox:checked").length > maxSelection) {
              $(this).prop("checked", false);
              alert("Please select a maximum of " + maxSelection + " items.");
          }
      })

ASP.NET CheckBoxList Operations with jQuery - Check Items By Text

//Check Items by Text
    var selText = ['Item-1','Item-3'];
    var $ctrls = $("[id*=CheckBoxList1]");
    for (var i = 0; i < selText.length; i++) {
        $ctrls.find('label:contains("' + selText[i] + '")').prev().prop('checked', true);
    }