Friday, December 23, 2011

How to validate dates using Javascript


here is the javascript function compare two dates.

        function validatedates() {
            
            var objPEndDate = document.getElementById('<%=txtDate1.ClientID%>').value;
            var objCExpiryDate = document.getElementById('<%=txtDate2.ClientID%>').value;


            var PEndDate = new Date(objPEndDate);
            var CExpiryDate = new Date(objCExpiryDate);


            if (CExpiryDate > PEndDate) {
                alert("Coupon Expiry Date should be less than Promotion End Date.");
                return false;
            }
            return true;
        }




HTML code


<asp:TextBox ID="txtDate2" CssClass="ICStyle ICStyle3Width" onchange="validatedates();" runat="server" />

Thursday, December 22, 2011

How to make any .Net Server Control visible invisible using Javascript

1. This is how you can make ASP.NET Server Control visible.

document.getElementById('<%= YourServerControlID.ClientID %>').style.display = "inline";

2. This is how you can make ASP.NET Server Control invisible.

document.getElementById('<%= YourServerControlID.ClientID %>').style.display = "none";

How to change SelectedIndex of Dropdownlist in Javascript


var oDDL = document.getElementById('<%=YourDropDownListID.ClientID%>');
oDDL.selectedIndex = 0;