Enjoy Javascript

Check check property check or not
   if ($('#chkAllowPreContest').prop('checked') == true) )

Drop down change function

 $('.ddlFieldType').change(function () {
}

Add css remove css
 $('#DivCapchaRestriction').removeClass('display-none');
        $('#DivCapchaRestriction').addClass('display-block');


Check undefinded or null
if ((chartName != undefined) && (chartName != null) && (chartName != "")) {
}

Prevent key on key press in text box
 $(".txt").keypress(function (e) {

        if (String.fromCharCode(e.which).match(/^[(<>)]*$/) || e.which == "45" || e.which

== "95" || e.which == "32" || e.which == "39" || e.which == "13" || e.which == "9" ||

e.which == "60" || e.which == "62" || e.which == "34" || e.which == "124" || e.which ==

"92" || e.which == "126" || e.which == "42") {
            return false;
        }
        else return true;

    });

Get value of text box
var shareHiddenField = $("#hdnIsShareNeeded").val();


Add remove parent element class
 $(this).parent().addClass("erroMsg");
  $(this).parent().removeClass('erroMsg');


Check numerice value
if (isNaN($(this).val())) {
                        alert('Please use only numbers  in password');
                                         }


checking for email
if (value == true) {
                    var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+

\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
                    if (filter.test($(this).val())) {
                        flag = true;
                        return true;
                    }
}

Get querystring using javascript
function getQueryStringParameterByName(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)')
                    .exec(window.location.search);

    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}


Confirm message using javascript
function ShowMsgForTimeZone() {
            if (confirm("You havent set Time Zone info,do you want to set it now?")) {
                window.location.href = "MyProfile.aspx";
            }
            else {
                //  $("#btnReload_Click").trigger("click");
                return false;
            }
        }

Comments