This SharePoint 2013 tutorial explains, how to solve $(document).ready(function() not working SharePoint 2013 list form error which comes in SharePoint 2013/2016 list forms like the new form, edit form or display form.
Here user wants to hide a field in a new form without custom c#.net code in SharePoint 2013/2016. I have tried with jquery and was trying to hide the field row in newform.aspx. But document.ready() is firing in newform.aspx.
Code snippet I was trying to use is:
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$("input[title*='FirstName']").val("Krishna.Vandanapu");
var field = $("input[title*='FirstName']"); // The * in title is needed because SharePoint 2013 uses "Required Field" on required fields.
field.parent().parent().parent().hide();
});
</script>
In the above code block I was trying to hide the row of FirstName field in the below screen with a default value as “Krishna.Vandanapu”. Since it is a mandatory field I set the default value.
The issue with the above code is I was missing the jquery reference library inclusion.
$(document).ready(function() not working SharePoint 2013 list form
We have to add the ajax library file http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js in the script to fire the $(document).ready function.
The final code will be as follows:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
alert("Krishna");
$("input[title*=Title]").val( "Title Value-1" );
$("input[title*='FirstName']").val("Krishna.Vandanapu"); //The * in title is needed because SharePoint 2013 uses "Required Field" on required fields.
var field = $("input[title*='FirstName']");
field.parent().parent().parent().hide();
});
</script>
The output will be as follows:
You may like following SharePoint jQuery tutorials:
- Cascading dropdown in SharePoint 2013/2016/Online using jQuery
- How to retrieve Query String Value using JQuery in SharePoint Online?
- How to bind current date to date picker using JQuery in SharePoint Online?
- Update People Picker Group field using Rest API and jQuery in SharePoint 2013
- Change default name in Suite Bar in SharePoint 2013/2016 and SharePoint Online
- Send Email with jQuery and REST API in SharePoint
- SharePoint 2016 crud operations using Rest API and jQuery on SharePoint list or document library
- Uncaught TypeError: Cannot read property get_current of undefined error SharePoint online jsom
Hope this SharePoint 2013 tutorial helps to resolve $(document).ready(function() not working SharePoint 2013 list form.
I am Krishna.Vandanapu a SharePoint architect working in IT from last 13+ years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019