Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, July 8, 2018 6:45 PM
Hello,
I have been reading this post: https://social.technet.microsoft.com/Forums/sharepoint/en-US/236ebd74-8d1d-45fd-a738-24aeefd0b2d5/get-the-sharepoint-form-field-id-using-javascript?forum=sharepointgeneralprevious
The reason is I would like to get the textbox (<input />) using the Internal name of the column instead the title as I have read in that post.
or Is there any way to transfrom the Internal name (Eg. "First Name User") to get the ID of this field?
<input type="text" value="" maxlength="25" id="First_x0020_Name_x0020_User12c0b2-b652-47f1-8adb-af671dabac2f_$TextField" title="First Name:" style="ime-mode : " class="ms-long ms-spellcheck-true">
Thank you!
All replies (1)
Monday, July 9, 2018 1:37 AM
Hi,
You could do this by JSOM if you don’t want to use jQuery as you shread.
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">
var fieldCollection;
var oneField = null;
function runCode() {
var clientContext = SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var webSite = clientContext.get_web();
taskList = webSite.get_lists().getByTitle("Tasks");
fieldCollection = taskList.get_fields();
this.oneField = fieldCollection.getByInternalNameOrTitle("Title");
this.oneField.set_description("MyNewFieldDescription");
this.oneField.update();
clientContext.load(this.fieldCollection);
clientContext.load(this.oneField);
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
}
}
function OnLoadSuccess(sender, args) {
var fieldInfo = '';
fieldInfo += 'Field Title: ' + oneField.get_title() + '\n' + 'Description: ' + oneField.get_description() + '\n';
alert(fieldInfo);
}
function OnLoadFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
<input id="Button1" type="button" value="Run Code" onclick="runCode()" />
</asp:Content>
Here is the link for your reference.
/en-us/previous-versions/office/developer/sharepoint-2010/ff409307%28v%3doffice.14%29
Best Regards,
Lee
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact [email protected].
Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.