I am trying to set a Readonly textbox2 text property to current year.
I am trying to set textbox2 text by using onchange() property on an above textbox1, this way after changing textbox2 text will be asigned as current year. Now the problem is, I have no idea how to work with date formats in jquery is to.
Here I am doing it like this $("#<%=FromYear.ClientID%>").val(Date.now);
but its not giving me year.
Asked
Active
Viewed 1,099 times
0

ABi
- 143
- 2
- 18
-
1if you want to set text property as year you need to write it .Text() instead of val() – ABi Aug 09 '16 at 21:37
4 Answers
1
Date.now
will return the function code of the Date.now()
function:
console.log(Date.now);
> function () { [native code] }
You want Date.getFullYear()
$("#<%=FromYear.ClientID%>").val(Date.getFullYear());

Nick Bull
- 9,518
- 6
- 36
- 58
0
$(document).ready(function(){
var today=new Date();
$('#DispalyDate').text("Full date=" + today.toDateString());
$('#FullYear').text("Full year=" + today.getFullYear());
$('#DayOfMonth').text("Day=" + today.getDate());
$('#GetMonth').text("Number of month=" + today.getMonth());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="DispalyDate"> </div>
<div id="FullYear"> </div>
<div id="DayOfMonth"> </div>
<div id="GetMonth"> </div>

Saffor
- 60
- 2
- 11