but value is not going to be set. same is working fine for HTML controls.
function calculateEnd() {
var dateval = new Date();
dateval.setYear($('#<%=ddlFSYear.ClientID %>').val()); dateval.setMonth($('#<%=ddlfsmonth.ClientID %>').val()); // value is not going to be set dateval.setDate($('#<%=ddlfsdate.ClientID %>').val()); // value is not going to be set
var val = 0;
if ($('#<%=cb1year.ClientID %>')[0].checked)
val = 1;
else if ($('#<%=cb2year.ClientID %>')[0].checked)
val = 2;
else if ($('#<%=cb3year.ClientID %>')[0].checked)
val = 3;
else if ($('#<%=cballyear.ClientID %>')[0].checked)
val = 10;
dateval.setYear(dateval.getFullYear()+ val);
dateval.setMonth(dateval.getMonth() - 1); $('#<%=LblFSmonth.ClientID%>').html(dateval.getDate() + "/" + (dateval.getMonth() + 1) + "/" + dateval.getFullYear()); }
int year = Convert.ToInt32(DateTime.Now.Year); ArrayList ayear = new ArrayList(); int i; for (i = year-1; i <= year + 1; i++) { ayear.Add(i); } ddlFSYear.DataSource = ayear; ddlFSYear.DataBind(); ddlFSYear.SelectedValue = DateTime.Now.Year.ToString();
i my above reply. i am calculating expiry date. its working fine. but not working for feb and march month.
like:
when i am selecting month feb2013 for one year exp date should me showing jan2014 but its showing feb2014 same problem for march and other months working fine.
atul2430
Member
142 Points
580 Posts
Jquery for post back ad calcualte date
Jan 18, 2013 09:04 AM|LINK
<script type="text/javascript"> $(document).ready(function () { $("input[id*=cb1year]").click(function () { calculateEnd(); }) $("input[id*=cb2year]").click(function () { calculateEnd(); }) $("input[id*=cb3year]").click(function () { calculateEnd(); }) $("input[id*=cballyear]").click(function () { calculateEnd(); }) $('#<%=ddlfsdate.ClientID %>, #<%=ddlfsmonth.ClientID %>, #<%=ddlFSYear.ClientID %>').change(function() { calculateEnd(); }) }); function calculateEnd() { var dateval = new Date(); dateval.setYear($('#<%=ddlFSYear.ClientID %>').val()); dateval.setMonth($('#<%=ddlfsmonth.ClientID %>').val()); dateval.setDate($('#<%=ddlfsdate.ClientID %>').val()); var val = 0; if ($('#<%=cb1year.ClientID %>')[0].checked) val = 1; else if ($('#<%=cb2year.ClientID %>')[0].checked) val = 2; else if ($('#<%=cb3year.ClientID %>')[0].checked) val = 3; else if ($('#<%=cballyear.ClientID %>')[0].checked) val = 10; dateval.setYear(dateval.getFullYear() + val); dateval.setMonth(dateval.getMonth() - 1); $("#LblFSmonth").html(dateval.getDate() + "/" + (dateval.getMonth() + 1) + "/" + dateval.getFullYear()); } </script>rnivash
Member
312 Points
62 Posts
Re: Jquery for post back ad calcualte date
Jan 18, 2013 10:12 AM|LINK
Are you using asp.net label control? then change the code to refer client id.
$("#<%=LblFSmonth.ClientID %>")
arunoyour
Participant
1089 Points
261 Posts
Re: Jquery for post back ad calcualte date
Jan 18, 2013 10:21 AM|LINK
$("#LblFSmonth") make it sure its not a server side control if so rearrange the codeVisit :: www.simplyasp.blogspot.com
Stay tune...Keep alive
atul2430
Member
142 Points
580 Posts
Re: Jquery for post back ad calcualte date
Jan 18, 2013 10:33 AM|LINK
Hi i changed
but value is not going to be set. same is working fine for HTML controls.
function calculateEnd() {
var dateval = new Date();
dateval.setYear($('#<%=ddlFSYear.ClientID %>').val());
dateval.setMonth($('#<%=ddlfsmonth.ClientID %>').val()); // value is not going to be set
dateval.setDate($('#<%=ddlfsdate.ClientID %>').val()); // value is not going to be set
var val = 0;
if ($('#<%=cb1year.ClientID %>')[0].checked)
val = 1;
else if ($('#<%=cb2year.ClientID %>')[0].checked)
val = 2;
else if ($('#<%=cb3year.ClientID %>')[0].checked)
val = 3;
else if ($('#<%=cballyear.ClientID %>')[0].checked)
val = 10;
dateval.setYear(dateval.getFullYear()+ val);
dateval.setMonth(dateval.getMonth() - 1);
$('#<%=LblFSmonth.ClientID%>').html(dateval.getDate() + "/" + (dateval.getMonth() + 1) + "/" + dateval.getFullYear());
}
rnivash
Member
312 Points
62 Posts
Re: Jquery for post back ad calcualte date
Jan 18, 2013 11:20 AM|LINK
Hi Atul,
Please share your html markup code for the dropdowns. The js script is working for the following markup code, written for testing purpose.
<asp:DropDownList ID="ddlfsdate" runat="server">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlfsmonth" runat="server">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
<asp:ListItem Text="4" Value="4"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlFSYear" runat="server">
<asp:ListItem Text="2001" Value="2001"></asp:ListItem>
<asp:ListItem Text="2002" Value="2002"></asp:ListItem>
<asp:ListItem Text="2003" Value="2003"></asp:ListItem>
<asp:ListItem Text="2004" Value="2004"></asp:ListItem>
</asp:DropDownList>
atul2430
Member
142 Points
580 Posts
Re: Jquery for post back ad calcualte date
Jan 18, 2013 11:43 AM|LINK
<asp:DropDownList ID="ddlfsmonth" runat="server" CssClass="activSelect" ValidationGroup="registrationvalidation"
Height="30px" Width="110px"
onselectedindexchanged="ddlfsmonth_SelectedIndexChanged">
<asp:ListItem Value="0">January</asp:ListItem>
<asp:ListItem Value="1">Febuary</asp:ListItem>
<asp:ListItem Value="2">March</asp:ListItem>
<asp:ListItem Value="3">April</asp:ListItem>
<asp:ListItem Value="4">May</asp:ListItem>
<asp:ListItem Value="5">June</asp:ListItem>
<asp:ListItem Value="6">July</asp:ListItem>
<asp:ListItem Value="7">August</asp:ListItem>
<asp:ListItem Value="8">September</asp:ListItem>
<asp:ListItem Value="9">October</asp:ListItem>
<asp:ListItem Value="10">November</asp:ListItem>
<asp:ListItem Value="11">December</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlFSYear" runat="server" CssClass="activSelect" ValidationGroup="registrationvalidation"
Height="30px" Width="100px"
onselectedindexchanged="ddlFSYear_SelectedIndexChanged"> /// getting date runtime
int year = Convert.ToInt32(DateTime.Now.Year);
ArrayList ayear = new ArrayList();
int i;
for (i = year-1; i <= year + 1; i++)
{
ayear.Add(i);
}
ddlFSYear.DataSource = ayear;
ddlFSYear.DataBind();
ddlFSYear.SelectedValue = DateTime.Now.Year.ToString();
</asp:DropDownList>
     
<span class="trackLabel">
Future Samachar Expiry:
</span>
<asp:Label ID="LblFSmonth" runat="server" class="trackLabel" Width="100px"></asp:Label>
</li>
rnivash
Member
312 Points
62 Posts
Re: Jquery for post back ad calcualte date
Jan 18, 2013 12:25 PM|LINK
Are you getting any js error or you are not getting the desired result?
I couldn't reproduce the issue that you are facing.
My code,
<%@ Page Title="" Language="C#" MasterPageFile="~/WebView.Master" AutoEventWireup="true" CodeBehind="JqueryPlayGround.aspx.cs" Inherits="MyWebView.JqueryPlayGround" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <script src="script/lib/jquery-1.8.3.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $("input[id*=cb1year]").click(function () { calculateEnd(); }) $("input[id*=cb2year]").click(function () { calculateEnd(); }) $("input[id*=cb3year]").click(function () { calculateEnd(); }) $("input[id*=cballyear]").click(function () { calculateEnd(); }) $('#<%=ddlfsdate.ClientID %>, #<%=ddlfsmonth.ClientID %>, #<%=ddlFSYear.ClientID %>').change(function () { calculateEnd(); }) }); function calculateEnd() { var dateval = new Date(); dateval.setYear($('#<%=ddlFSYear.ClientID %>').val()); dateval.setMonth($('#<%=ddlfsmonth.ClientID %>').val()); dateval.setDate($('#<%=ddlfsdate.ClientID %>').val()); var val = 0; if ($('#<%=cb1year.ClientID %>')[0].checked) val = 1; else if ($('#<%=cb2year.ClientID %>')[0].checked) val = 2; else if ($('#<%=cb3year.ClientID %>')[0].checked) val = 3; else if ($('#<%=cballyear.ClientID %>')[0].checked) val = 10; dateval.setYear(dateval.getFullYear() + val); dateval.setMonth(dateval.getMonth() - 1); $("#<%=LblFSmonth.ClientID %>").html(dateval.getDate() + "/" + (dateval.getMonth() + 1) + "/" + dateval.getFullYear()); } </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <form id="form1" runat="server"> <asp:DropDownList ID="ddlfsdate" runat="server" OnSelectedIndexChanged="ddlfsdate_SelectedIndexChanged"> <asp:ListItem Text="1" Value="1"></asp:ListItem> <asp:ListItem Text="2" Value="2"></asp:ListItem> <asp:ListItem Text="3" Value="3"></asp:ListItem> <asp:ListItem Text="4" Value="4"></asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="ddlfsmonth" runat="server" OnSelectedIndexChanged="ddlfsmonth_SelectedIndexChanged"> <asp:ListItem Value="0">January</asp:ListItem> <asp:ListItem Value="1">Febuary</asp:ListItem> <asp:ListItem Value="2">March</asp:ListItem> <asp:ListItem Value="3">April</asp:ListItem> <asp:ListItem Value="4">May</asp:ListItem> <asp:ListItem Value="5">June</asp:ListItem> <asp:ListItem Value="6">July</asp:ListItem> <asp:ListItem Value="7">August</asp:ListItem> <asp:ListItem Value="8">September</asp:ListItem> <asp:ListItem Value="9">October</asp:ListItem> <asp:ListItem Value="10">November</asp:ListItem> <asp:ListItem Value="11">December</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="ddlFSYear" runat="server"> </asp:DropDownList> <asp:CheckBox ID="cb1year" runat="server" Text="1 year" /> <asp:CheckBox ID="cb2year" runat="server" Text="2 year" /> <asp:CheckBox ID="cb3year" runat="server" Text="3 year" /> <asp:CheckBox ID="cballyear" runat="server" Text="All" /> <br /> <asp:Label ID="LblFSmonth" runat="server" Text="Label" Width="100px"></asp:Label> </form> </asp:Content>using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace MyWebView { public partial class JqueryPlayGround : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { int year = Convert.ToInt32(DateTime.Now.Year); ArrayList ayear = new ArrayList(); int i; for (i = year - 1; i <= year + 1; i++) { ayear.Add(i); } ddlFSYear.DataSource = ayear; ddlFSYear.DataBind(); ddlFSYear.SelectedValue = DateTime.Now.Year.ToString(); } } protected void ddlfsdate_SelectedIndexChanged(object sender, EventArgs e) { string abc = ""; abc = "dsds"; LblFSmonth.Text = abc; } protected void ddlfsmonth_SelectedIndexChanged(object sender, EventArgs e) { } } }atul2430
Member
142 Points
580 Posts
Re: Jquery for post back ad calcualte date
Jan 19, 2013 03:59 AM|LINK
i solved this now it is workinfg fine..
<%-- // date calculator--%>
<script type="text/javascript">
$(document).ready(function() {
$("input[id*=cb1year]").click(function() {
calculateEnd();
})
$("input[id*=cb2year]").click(function() {
calculateEnd();
})
$("input[id*=cb3year]").click(function() {
calculateEnd();
})
$("input[id*=cballyear]").click(function() {
calculateEnd();
})
$('#<%=ddlfsdate.ClientID %>, #<%=ddlfsmonth.ClientID %>, #<%=ddlFSYear.ClientID %>').change(function() {
calculateEnd();
})
});
function calculateEnd() {
var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
var dateval = new Date();
dateval.setYear($('#<%=ddlFSYear.ClientID %>').val());
dateval.setMonth($('#<%=ddlfsmonth.ClientID %>').val());
var val = 0;
if ($('#<%=cb1year.ClientID %>')[0].checked)
val = 1;
else if ($('#<%=cb2year.ClientID %>')[0].checked)
val = 2;
else if ($('#<%=cb3year.ClientID %>')[0].checked)
val = 3;
else if ($('#<%=cballyear.ClientID %>')[0].checked)
val = 10;
else
val = 0;
if (val > 0) {
dateval.setYear(dateval.getFullYear() + val);
dateval.setMonth(dateval.getMonth() - 1);
$('#<%=LblFSmonth.ClientID%>').html(months[(dateval.getMonth())] + " - " + dateval.getFullYear());
}
else
$('#<%=LblFSmonth.ClientID%>').html("");
}
</script>
atul2430
Member
142 Points
580 Posts
Re: Jquery for post back ad calcualte date
Jan 30, 2013 04:43 AM|LINK
Hello guys,
i my above reply. i am calculating expiry date. its working fine. but not working for feb and march month.
like:
when i am selecting month feb2013 for one year exp date should me showing jan2014 but its showing feb2014 same problem for march and other months working fine.
plz tell me where is problem