Scenario:
You need to get the full name of the logged in SharePoint user using Javascript so you can fill a textbox (or whatever your needs are). This is actually more simple than you would think.

Log into your SharePoint site and look in the top portion of the page where your name appears. You can then ‘View Source’ in your browser and search for that name. When it is found, you will see that there is an auto-generated form item called something like zz8_Menu or zz16_Menu (your number may be different). Using whatever you find is being used on that site, add the following Javascript function:


function getLoginName()
{
	var Loginname = document.getElementById("zz16_Menu").innerHTML; 
	var start = Loginname.indexOf("") + 6; 
	var end = Loginname.indexOf("");
	var nameOnly = Loginname.substring(start, end); 
return nameOnly;
}

Then, you can use that function anywhere in your page top populate any form item, or use in a document.write statement, or whatever you’d like.