Showing posts with label Listform. Show all posts
Showing posts with label Listform. Show all posts

Saturday, December 13, 2014

Get Current User name using JQuery in sharepoint 2013

Here is the code to fetch current user name ( logged in user name ) using Jquery , this can be user on content editor webpart or list form .

things to take care before u use below code
1. download jquery-1.4.2.min.js and jquery.SPServices-0.5.7.min.js and
2. upload both the downloaded files to style library under new folder named as js.


<script language="javascript" src="../../Style Library//js/jquery-1.4.2.min.js" type="text/javascript"></script>  
<script language="javascript" src="../../Style Library/js/jquery.SPServices-0.5.7.min.js" type="text/javascript"></script>
<script type="text/javascript">
 
//to make sure above added script links are loaded on page
  $(document).ready(function() {
 
// to get formlabel control
  if (document.getElementById("formlabel") != null)
{

document.getElementById("formlabel").innerText =  $().SPServices.SPGetCurrentUser(
{fieldName:"Title",
debug:false
});
}
</script>

formlabel is html label , innertext of label is set to current logged in user name programmatically using above code.