Friday, April 20, 2012
Javascript Datetime validation
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function validate()
{
var fromDate = document.getElementById("txtStartdate").value;
var toDate = document.getElementById("txtEnddate").value;
if (fromDate == '' || toDate == '')
{
alert("Enter both start and end dates to click search");
}
else
{
if (Date.parse(fromDate) > Date.parse(toDate))
{
alert("Invalid Date Range!\nStart Date cannot be after End Date!")
return false;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClientClick="validate();"
Text="Button" />
<asp:TextBox ID="txtStartdate" runat="server"></asp:TextBox>
<asp:TextBox ID="txtEnddate" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment