Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a custom SharePoint list with about 20 fields. If possible, I wanted to include a hyperlink on the display, edit, new form so when the user clicks the hyperlink, their login name is displayed in the text area.

So something like this:

<a onclick="__doPostBack('GetCurrent().Name');">Approve</a>
share|improve this question

2 Answers 2

For 2010:

Add this to the page in a content editor webpart, or add to the page layout

<script language="javascript" type="text/javascript">
function DoAction() {
    var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var user = web.get_currentUser();
    clientContext.load(user);
    clientContext.executeQueryAsync(function() {
        var textbox = $jQuery("#ctl00_m_g_46c97b47_3773_4a68_8f4f_17d5faa8a9f2_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_...");
        textbox.val(user.get_loginName());
        //do whatever else here
    }, function() {
        alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
    });
} 
</script>

Then add a custom list action in sharepoint designer 2010, with this as the navigate url:

javascript:DoAction()

http://blog.furuknap.net/adding-custom-actions-in-sharepoint-designer-2010

For 2007:

Try using SPServices

share|improve this answer

You could use this javascript trick to get the current user from the Welcome link

function getCurrentUser()
  {
    var tags = document.getElementsByTagName('a');

    for (var i=0; i < tags.length; i++)
      {

    if(tags[i].innerText.substr(0,7) == 'Welcome')

          {

        return tags[i].innerText.substr(8,tags[i].innerText.length);

          } 

       }

  }

Be aware that in a multi lingual site the Welcome will be different :) And that also this is just a little dirty hack Hope this helps anyway

share|improve this answer
    
thanks for your input but when i tried to implement this i get the following error: An error occurred during the processing of disform1.aspx. only content controls are allowed directly in a content page that contains content controls. –  user2825 Apr 19 '11 at 18:39
    
are you using sharepoint designer for this? if so here is some example. link. To troubleshoot your error will need to see the code –  Renzo Apr 19 '11 at 19:47
    
i appreciate your help. i need to know where to place your script on the form so it won't throw and error. –  user2825 Apr 19 '11 at 20:10
1  
This is a very bad idea since you are tying yourself to various unknows. Is there a welcome link on the page? Is it rendered using just the innertext 'Welcome'. All in all, please never ever do this. –  Wouter - SharePoint MVP Apr 20 '11 at 13:59
    
that is wht I said that this a ltitle dirty hack, I am not saying is best practices! –  Renzo Apr 21 '11 at 6:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.