here i have taken two Text box 1 for Enroll date and 1 for Expire date.When i enter Enroll date,Expire date will automatically fill up on exact 1 year gap of Enroll date with proper format(dd/mm/yyyy).
Ans:-
ChangeExpDtByIncDt.aspx:-
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ChangeExpDtByIncDt.aspx.vb" Inherits="ChangeExpDtByIncDt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Auto Fillup Expire Date a year by Inception Date Page</title>
<script language="javascript" type="text/javascript">
function validDateFormat(obj) {
if ((event.keyCode > 46 && event.keyCode < 58)) {
var keycharacter = 0;
tVal = document.getElementById(obj).value;
keycharacter = String.fromCharCode(event.keyCode);
tVal = tVal + keycharacter;
if (event.keyCode == 47) {
if (tVal.length == 3) {
return true;
} else if (tVal.length == 6) {
return true;
}
return false;
}
if (tVal.length <= 10) {
if (parseInt(keycharacter) == 0 && tVal == 0 && tVal.length > 1) {
return false;
}
//Year
var arrDate = tVal.split("/");
if (parseInt(keycharacter) == 0 && tVal.length == 7) {
return false;
}
//Day
if (tVal.length == 2) {
var arrDate = tVal.split("/");
if (tVal.length == 2 && arrDate[0] <= 31) {
document.getElementById(obj).value = tVal + "/";
return false;
} else { return false; }
}
//Month
if (tVal.length == 5) {
var arrDate = tVal.split("/");
if ((tVal.length == 5 && arrDate[1] <= 12) && (arrDate[1] > 0)) {
document.getElementById(obj).value = tVal + "/";
return false;
} else { return false; }
}
} else { return false; }
} else { return false; }
}
function ValidMemberExp() {
var tVal = document.getElementById('txtEnrollDate').value;
if (tVal != "") {
//Inception Date
var incep_date = tVal.split("/");
var bday1 = parseInt(incep_date[0]);
var bmo1 = (parseInt(incep_date[1]) - 1);
var byr1 = parseInt(incep_date[2]);
if (tVal.length != 10) {
alert("Invalid Date\nPlease Make Sure Date Should be dd/MM/yyyy");
document.getElementById('txtExpDate').value = "";
document.getElementById('txtEnrollDate').focus();
return false;
}
var nodays_mnt = parseInt(32 - new Date(byr1, bmo1, 32).getDate());
// alert(nodays_mnt);
if (bday1 > nodays_mnt) {
alert("The no of Days For This Month is " + nodays_mnt);
document.getElementById('txtExpDate').value = "";
document.getElementById('txtEnrollDate').focus();
return false;
}
if ((tVal.substr(2, 1) != "/") || (tVal.substr(5, 1) != "/")) {
alert("Invalid Date\nPlease Make Sure Date Should be dd/MM/yyyy");
document.getElementById('txtEnrollDate').focus();
return false;
}
}
// ********** Validation For Exiry Date ********//
if (tVal != "" && tVal.length == 10) {
var emo, eday, eyr;
var incep_date1 = tVal.split("/");
var bday = incep_date1[0];
var bmo = incep_date1[1];
var byr = parseInt(incep_date1[2]);
var isLeap = new Date(byr, 1, 29).getDate();
var s = incep_date1[2].length;
//=============DATE EXPIRY DATE ============//
var edate1 = tVal.split("/");
var bday1 = edate1[0];
var bmo1 = edate1[1];
var byr1 = edate1[2];
ModMonth = parseFloat(bmo1) + 11;
var modifiedDate = new Date(byr1, ModMonth, bday1);
var CardExpdate = new Date(modifiedDate - 1); // 1 Day Minus //
var t_day = CardExpdate.getDate();
var t_month = CardExpdate.getMonth() + 1;
var t_year = CardExpdate.getFullYear();
if ((t_month == "1") || (t_month == "2") || (t_month == "3") || (t_month == "4") || (t_month == "5") || (t_month == "6") || (t_month == "7") || (t_month == "8") || (t_month == "9")) {
t_month = "0" + t_month;
}
if ((t_day == "1") || (t_day == "2") || (t_day == "3") || (t_day == "4") || (t_day == "5") || (t_day == "6") || (t_day == "7") || (t_day == "8") || (t_day == "9")) {
t_day = "0" + t_day;
}
var expdate = t_day + "/" + t_month + "/" + t_year;
document.getElementById('txtExpDate').value = expdate;
document.getElementById('TextBox1').value = document.getElementById('txtEnrollDate').value;
document.getElementById('TextBox2').value = document.getElementById('txtExpDate').value;
}
}
</script>
<script language="javascript" type="text/javascript">
function disable()
{
if (event.button == 2)
{
alert("Sorry no rightclick on this page.");
}
// setInterval("window.clipboardData.setData('text','')",5);
}
</script>
</head>
<body style="margin:0px;" onmousedown="disable()" onkeydown="disable()" onload="ValidMemberExp()" bgcolor="white">
<form id="form1" runat="server">
<div>
<center>
<p>Auto Fillup Expire Date a year by Inception Date</p>
<p>
Enrollment Date :
<asp:TextBox ID="txtEnrollDate" runat="server" Width="175px" MaxLength="10"></asp:TextBox>
Expiry Date :
<asp:TextBox ID="txtExpDate" runat="server" MaxLength="10" Width="175px"></asp:TextBox>
<br />
<br />
CardIssueDate :
<asp:TextBox ID="TextBox1" runat="server" Width="175px" MaxLength="10"></asp:TextBox>
CardExpDate :
<asp:TextBox ID="TextBox2" runat="server" MaxLength="10" Width="175px"></asp:TextBox>
</p>
</center>
</div>
</form>
</body>
</html>
Ans:-
ChangeExpDtByIncDt.aspx:-
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ChangeExpDtByIncDt.aspx.vb" Inherits="ChangeExpDtByIncDt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Auto Fillup Expire Date a year by Inception Date Page</title>
<script language="javascript" type="text/javascript">
function validDateFormat(obj) {
if ((event.keyCode > 46 && event.keyCode < 58)) {
var keycharacter = 0;
tVal = document.getElementById(obj).value;
keycharacter = String.fromCharCode(event.keyCode);
tVal = tVal + keycharacter;
if (event.keyCode == 47) {
if (tVal.length == 3) {
return true;
} else if (tVal.length == 6) {
return true;
}
return false;
}
if (tVal.length <= 10) {
if (parseInt(keycharacter) == 0 && tVal == 0 && tVal.length > 1) {
return false;
}
//Year
var arrDate = tVal.split("/");
if (parseInt(keycharacter) == 0 && tVal.length == 7) {
return false;
}
//Day
if (tVal.length == 2) {
var arrDate = tVal.split("/");
if (tVal.length == 2 && arrDate[0] <= 31) {
document.getElementById(obj).value = tVal + "/";
return false;
} else { return false; }
}
//Month
if (tVal.length == 5) {
var arrDate = tVal.split("/");
if ((tVal.length == 5 && arrDate[1] <= 12) && (arrDate[1] > 0)) {
document.getElementById(obj).value = tVal + "/";
return false;
} else { return false; }
}
} else { return false; }
} else { return false; }
}
function ValidMemberExp() {
var tVal = document.getElementById('txtEnrollDate').value;
if (tVal != "") {
//Inception Date
var incep_date = tVal.split("/");
var bday1 = parseInt(incep_date[0]);
var bmo1 = (parseInt(incep_date[1]) - 1);
var byr1 = parseInt(incep_date[2]);
if (tVal.length != 10) {
alert("Invalid Date\nPlease Make Sure Date Should be dd/MM/yyyy");
document.getElementById('txtExpDate').value = "";
document.getElementById('txtEnrollDate').focus();
return false;
}
var nodays_mnt = parseInt(32 - new Date(byr1, bmo1, 32).getDate());
// alert(nodays_mnt);
if (bday1 > nodays_mnt) {
alert("The no of Days For This Month is " + nodays_mnt);
document.getElementById('txtExpDate').value = "";
document.getElementById('txtEnrollDate').focus();
return false;
}
if ((tVal.substr(2, 1) != "/") || (tVal.substr(5, 1) != "/")) {
alert("Invalid Date\nPlease Make Sure Date Should be dd/MM/yyyy");
document.getElementById('txtEnrollDate').focus();
return false;
}
}
// ********** Validation For Exiry Date ********//
if (tVal != "" && tVal.length == 10) {
var emo, eday, eyr;
var incep_date1 = tVal.split("/");
var bday = incep_date1[0];
var bmo = incep_date1[1];
var byr = parseInt(incep_date1[2]);
var isLeap = new Date(byr, 1, 29).getDate();
var s = incep_date1[2].length;
//=============DATE EXPIRY DATE ============//
var edate1 = tVal.split("/");
var bday1 = edate1[0];
var bmo1 = edate1[1];
var byr1 = edate1[2];
ModMonth = parseFloat(bmo1) + 11;
var modifiedDate = new Date(byr1, ModMonth, bday1);
var CardExpdate = new Date(modifiedDate - 1); // 1 Day Minus //
var t_day = CardExpdate.getDate();
var t_month = CardExpdate.getMonth() + 1;
var t_year = CardExpdate.getFullYear();
if ((t_month == "1") || (t_month == "2") || (t_month == "3") || (t_month == "4") || (t_month == "5") || (t_month == "6") || (t_month == "7") || (t_month == "8") || (t_month == "9")) {
t_month = "0" + t_month;
}
if ((t_day == "1") || (t_day == "2") || (t_day == "3") || (t_day == "4") || (t_day == "5") || (t_day == "6") || (t_day == "7") || (t_day == "8") || (t_day == "9")) {
t_day = "0" + t_day;
}
var expdate = t_day + "/" + t_month + "/" + t_year;
document.getElementById('txtExpDate').value = expdate;
document.getElementById('TextBox1').value = document.getElementById('txtEnrollDate').value;
document.getElementById('TextBox2').value = document.getElementById('txtExpDate').value;
}
}
</script>
<script language="javascript" type="text/javascript">
function disable()
{
if (event.button == 2)
{
alert("Sorry no rightclick on this page.");
}
// setInterval("window.clipboardData.setData('text','')",5);
}
</script>
</head>
<body style="margin:0px;" onmousedown="disable()" onkeydown="disable()" onload="ValidMemberExp()" bgcolor="white">
<form id="form1" runat="server">
<div>
<center>
<p>Auto Fillup Expire Date a year by Inception Date</p>
<p>
Enrollment Date :
<asp:TextBox ID="txtEnrollDate" runat="server" Width="175px" MaxLength="10"></asp:TextBox>
Expiry Date :
<asp:TextBox ID="txtExpDate" runat="server" MaxLength="10" Width="175px"></asp:TextBox>
<br />
<br />
CardIssueDate :
<asp:TextBox ID="TextBox1" runat="server" Width="175px" MaxLength="10"></asp:TextBox>
CardExpDate :
<asp:TextBox ID="TextBox2" runat="server" MaxLength="10" Width="175px"></asp:TextBox>
</p>
</center>
</div>
</form>
</body>
</html>
ChangeExpDtByIncDt.aspx.vb:-
Partial Class ChangeExpDtByIncDt
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtEnrollDate.Attributes.Add("onfocusout", "return ValidMemberExp()")
txtEnrollDate.Attributes.Add("onkeypress", "return validDateFormat('txtEnrollDate')")
End Sub
End Class
No comments:
Post a Comment