Unable to auto fill the fields on sharepoint list Newform.aspx with current user information

Feb 16 at 7:24 AM
Hello

I have a sharepoint list which I would like the NewForm.aspx fields to be auto filled with the current user information. I have successfully confirmed that the Spservices is able to get the current user name but I am not able to pass this value to the NewForm.aspx field.

Here is my code. the alert (username); works fine but $("input[Title='Staffname']").val(username); does not work
<script language="javascript" type="text/javascript"> var username = $().SPServices.SPGetCurrentUser({ fieldName: "Name" }); $("input[Title='Staffname']").val(username); alert (username); </script> we run sharepoint 2010 enterprise.
Let me also add that I customized this form in InfoPath 2010.. could this be the problem? but the field name remains the same.

thanks
Feb 17 at 7:12 PM
This is how I do it on a custom NewForm (the kind you get in SPD, List > Forms > New > New Item Form):

In a script block in the aspx page, inside a $(document).ready(function() block,
    // get the current user
    var thisUserName = $().SPServices.SPGetCurrentUser({
        fieldName: "Title",
        debug: false
    });
    
    // autofill document author
    $().SPServices.SPFindPeoplePicker({
        peoplePickerDisplayName: "Document/Artifact author",
        valueToSet: thisUserName,
        checkNames: true
    });
Feb 23 at 1:27 PM
Thanks I will try it out

Mar 5 at 12:19 PM
I frequently complement SPServices with functionality in Alexander Buatz's excellent library named spjs-utility.js. The library includes such functionality as getting and setting field values in a SharePoint form. Here's a link to the page on his site (spjsblog.com), that describes how to set and get field values: http://spjsblog.com/2010/05/28/get-or-set-value-for-sharepoint-field-in-newform-editform-and-dispform-get-only-in-dispform/