$(document).ready(function() not working SharePoint 2013/2016 list form

Document.ready() not working in list new form-2013

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.

SharePoint deveopment training course

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.

Document.ready() not working in list new form-2013
Document.ready() not working in list new form-2013

The issue with the above code is I was missing the jquery reference library inclusion.

Solution: $(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=”http://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:

Document.ready() not working in list new form online
$(document).ready(function() not working SharePoint 2013 list form

You may like following SharePoint jQuery tutorials:

Hope this SharePoint 2013 tutorial helps to resolve $(document).ready(function() not working SharePoint 2013 list form.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Krishna Vandanapu

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

View all posts by Krishna Vandanapu →