Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers 2

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

var contentTypeId = $.query.get('ContentTypeId');
share|improve this answer
add comment
up vote 3 down vote accepted

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");
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.