Thursday 13 December 2012

JQuery to display today's date on list column using HTML tag


1.       Create a column in my list called "DateField", use the calculation field with ="<B></B>" as the calculation
2.        Create a Content Edit Web Part and use the source below:


<script src="/path/jquery.min.js" type="text/javascript"></script>
<script src="/path/jquery-1.4.2.min.js" type="text/javascript"></script>

<script type="text/javascript">

//get current date
var currentTime = new Date()
var month = currentTime.getMonth()+1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var CurrentDate = month + "/"+ day + "/" + year

//check for our html tag to replace the value
$(document).ready(function(){
$(".ms-vb2:contains('<B')").each(function(){
var tempB = document.createElement ("B");
tempB.style.cursor = "pointer";
tempB.innerHTML = $(this).text();
$(this).text(CurrentDate);
$(this).append(tempB);
});
});

</script>

No comments:

Post a Comment