Adding jQuery to a SharePoint Page: Step One, Always

No matter how many times I add jQuery to a page in SharePoint, this is absolutely *always* the first thing that I do:

<script language="javascript" type="text/javascript" src="/Scripts/jquery-1.5.min.js"></script>
<script language="javascript" type="text/javascript" src="/Scripts/jquery.SPServices-0.6.1.min.js"></script>
<script language="javascript" type="text/javascript">

	$(document).ready(function() {

		alert("jQuery");

	});

</script>

SNAGHTML168ed5faIf that alert in line 7 which is wrapped in a $(document).ready fires, then my script references are good. I can’t tell you how many times I’ve talked people through that simple step. It even hangs me up, so it’s always good to do that alert first. (Sure, the alert can say “Bob’s your Uncle” or “Strawberry Jam”, but alert *something*.)

Similar Posts

51 Comments

  1. I am adding new Newform.aspx and tryiung to use jquery to show/hide fields. I dont know which js files to use. want to avoid cdn. using “jquery-1.10.2.js” from above link but not getting alert. please advise

  2. Hey Marc,

    I have to make 2 single line text fields to be mandatory after selecting a value from (Status) dropdown list. Could you please provide me a jquery to make the work done

  3. Please find the Jquery which I have tried.

    //status is the dropdown list name
    $(‘Status’).change(function () {
    if (this.value == ‘Review’) {
    $(‘Cause’).css(‘display’, ‘block’);
    }
    else {
    $(‘Cause’).css(‘display’, ‘none’);
    }
    });

    1. KAD:

      Your selectors don’t make much sense. You need to use a DOM inspector like Firebug to look at the elements you want to select. for instance, rather than $(‘Status’), you probably need something like $(“select[Title=’Status’]”), assuming you have < 20 options for Status M.

  4. Hey Mark, long time follower and used the trusty SP services in the past. Having the most simplest of issues though testing the alert, it ain’t showing up. Added the source under the PlaceHolder and made sure the reference is correct (to a local doc library) – I can click the js files and they open up fine in SPD but no go on the alert. Tried the new 2013.01 and even reverted back to the 7.1a and still nothing… its driving me nuts something so simple, yet it aint coming up!

  5. Just wanted to say great information and thank you for the work you put into SP Services and your blog Marc!

    Thanks Again!
    Dan

  6. IM new and just started with the request to populate user data on a form I read your instructions as requested and FAQ’s,

    I’m using SP Designer 2013 using the recommended route to add the code to the page I get the following error
    “Unknown server tag. Correlation ID: ee049f9c-d0ed-1000-69ef-a3b8b288aab5. ”

    So I went back and tried to add your section on the first thing you add to every page to get the listed error.

    I think I’m adding the code to the wrong place on the page. where should I add the code listed in the article?

  7. Hi,

    I never had this issue in SP 2007 and SP 2010. But When I am trying to add the reference in SP 2013 List NewForm.aspx it is not firing. Any idea why? Please suggest me on this. Thanks in advance !.


    Rao

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.