1

I've been trying to access the ContentTypeId in the NewForm.aspx querystring. Knowing that will allow me to set up conditional statements to display information specific to a Content Type. My question:

Does anyone have some code to share that demonstrates, with jQuery or javascript, how to get the value of ContentTypeId parameter in the querystring?

Thanks in advance!

Arnold

3

Or, without jQuery:

function querySt(stKey) {
    stQString = window.location.search.substring(1);
    arKeyValues = stQString.split("&");
    for (i = 0; i < arKeyValues.length; i++) {
        arPairs = arKeyValues[i].split("=");
        if (arPairs[0] == stKey) {
            return arPairs[1];
        }
    }
};

var contentTypeId = querySt("ContentTypeId");
1
  • Thanks guys! Sebastien, I'm sure your code works in 99% of cases, but for some reason, that code breaks my jQuery floating and draggable. I tried using that very code snippet yesterday...but no joy. Jim Bob, your javascript worked perfectly, so I'm accepting your answer. However, you guys should check this out: blogs.microsoft.co.il/blogs/itaysk/archive/2008/11/30/… Itay uses a SharePoint function that's not well-documented to get querystring parameters. Works well. -Arn
    – user1743
    Nov 24 '10 at 17:16
1

With the following jQuery extension (see here), you could use the following code to get your ContentTypeId :

var contentTypeId = $.query.get('ContentTypeId');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy