Next i have two asp.net textbox1 and textbox2 if user select from dropdownlist Feb-2019
Then in textbox1 i want thow Feb Month First Date In textbox1 and last date in textbox2
According to your description, i made dmeo for you. i set the dropdownlist value base on month. then i set textbox value by month.
<script>
$(document).ready(function () {
$('#DropDownList1').change(function () {
var m31 = [1, 3, 5, 7, 8, 10, 12]
var m30 = [4, 6, 9, 11]
var value = parseInt($('#DropDownList1').val());
if (m31.includes(value)) {
$('#TextBox1').val(1);
$('#TextBox2').val(31);
}
else if (m30.includes(value)) {
$('#TextBox1').val(1);
$('#TextBox2').val(30);
}
else {
$('#TextBox1').val(1);
$('#TextBox2').val(28);
}
});
});
</script>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="2">Feb-2019</asp:ListItem>
<asp:ListItem Value="3">Mar-2019</asp:ListItem>
<asp:ListItem Value="4">Apr-2019</asp:ListItem>
<asp:ListItem Value="5">May-2019</asp:ListItem>
</asp:DropDownList>
<br />
<br />
First date:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
Last date:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
The result:
Best regards,
Sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
if seelct then it should show full date like this format
01-Feb-2019 28-Feb-2019
You can try below code, I get the year by getFullYear(), get the month by getMonth() + 1, get tha firstDay by new Date(y, m, 1).getDate(), get the lastDay by new Date(y, m, 0).getDate().
<script>
$(document).ready(function () {
$('#DropDownList1').change(function () {
var y = new Date($('#DropDownList1').val()).getFullYear();
var m = new Date($('#DropDownList1').val()).getMonth() + 1;
var firstDay = new Date(y, m, 1).getDate();
var lastDay = new Date(y, m, 0).getDate();
$("#TextBox1").val(firstDay + "-" + GetMonthName(m) + "-" + y);
$("#TextBox2").val(lastDay + "-" + GetMonthName(m) + "-" + y);
});
function GetMonthName(monthNumber) {
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
return months[monthNumber - 1];
}
});
</script>
<div>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Feb-2019</asp:ListItem>
<asp:ListItem>Mar-2019</asp:ListItem>
<asp:ListItem>Apr-2019</asp:ListItem>
<asp:ListItem>May-2019</asp:ListItem>
</asp:DropDownList>
<br />
<br />
First date:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
Last date:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
The result:
Best regards,
sam
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
293 Points
676 Posts
How to bind first date and last date of selected date
Dec 04, 2019 04:01 AM|Gopi.MCA|LINK
Hello
I have one asp.net dropdownlist in that for example data will be like this
Feb-2019
Mar-2019
Apr-2019
May-2019
Next i have two asp.net textbox1 and textbox2 if user select from dropdownlist Feb-2019
Then in textbox1 i want thow Feb Month First Date In textbox1 and last date in textbox2
how to do using jquery or javascript without postback
Thanking You
Contributor
2096 Points
1040 Posts
Re: How to bind first date and last date of selected date
Dec 04, 2019 05:21 AM|Khuram.Shahzad|LINK
first you need to get the selected value by
Contributor
3370 Points
1409 Posts
Re: How to bind first date and last date of selected date
Dec 04, 2019 08:30 AM|samwu|LINK
Hi Gopi.MCA,
According to your description, i made dmeo for you. i set the dropdownlist value base on month. then i set textbox value by month.
The result:
Best regards,
Sam
Member
293 Points
676 Posts
Re: How to bind first date and last date of selected date
Dec 04, 2019 12:12 PM|Gopi.MCA|LINK
Hello
For Example i have shown this
It may be Apr-2014
MAr-2013
if seelct then it should show full date like this format
01-Feb-2019 28-Feb-2019
Thanking You
Contributor
3370 Points
1409 Posts
Re: How to bind first date and last date of selected date
Dec 05, 2019 06:57 AM|samwu|LINK
Hi Gopi.MCA,
You can try below code, I get the year by getFullYear(), get the month by getMonth() + 1, get tha firstDay by new Date(y, m, 1).getDate(), get the lastDay by new Date(y, m, 0).getDate().
<script> $(document).ready(function () { $('#DropDownList1').change(function () { var y = new Date($('#DropDownList1').val()).getFullYear(); var m = new Date($('#DropDownList1').val()).getMonth() + 1; var firstDay = new Date(y, m, 1).getDate(); var lastDay = new Date(y, m, 0).getDate(); $("#TextBox1").val(firstDay + "-" + GetMonthName(m) + "-" + y); $("#TextBox2").val(lastDay + "-" + GetMonthName(m) + "-" + y); }); function GetMonthName(monthNumber) { var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; return months[monthNumber - 1]; } }); </script> <div> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>Feb-2019</asp:ListItem> <asp:ListItem>Mar-2019</asp:ListItem> <asp:ListItem>Apr-2019</asp:ListItem> <asp:ListItem>May-2019</asp:ListItem> </asp:DropDownList> <br /> <br /> First date:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> Last date:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </div>
The result:
Best regards,
sam
Contributor
2096 Points
1040 Posts
Re: How to bind first date and last date of selected date
Dec 05, 2019 08:05 AM|Khuram.Shahzad|LINK
Please check the link
http://jsfiddle.net/kn5f894L/1/#&togetherjs=2TI5ODTdeR