Getting Content Type within EditForm.aspx

Nov 14, 2013 at 12:54 AM
I'm struggling with the syntax to obtain the "Content Type" when I'm on an EditForm.aspx.

Basically I'm using SPServicesCascading and I want to filter values from a list based on the content type selected. I have a field in my reference list that I will use to Query the correct data from my list.

My EditForm.aspx has the "Content Type" dropdown, but I cannot seem to figure out the exact synatx to obtain the value within drop down.

At this point, I've created 2 "Parent" content types. Each parent content type has 8 different content types as child content types. The drop down lists the 16 child content types. My ideal situation would be able to determine the child content type, traverse up and determine which parent it is associated with. Then based on this value, I will use CAML to filter my results in my 3rd cascading drop down menu.

I'm not a Javascript person, but I'm trying to use:
var strContentType = $("input[title$='Content Type']").val();
alert("Content Type: " + strContentType);
Everytime the alert comes back Content Type: Undefined. I've also tried ='Content_x0020_Type', but that gives me the same result.

Any help would be greatly appreciated.
Coordinator
Nov 14, 2013 at 2:19 PM
I'm not sure that you need to care what content type you're working with. If you add the SPCascadingDropdowns calls to the page and there are no matches on the columns, the call should fail gracefully.

M.
Coordinator
Nov 14, 2013 at 2:22 PM
p.s. You can simply call GetListItem for the current item and get the Content Type.

M.
Nov 15, 2013 at 2:52 AM
Edited Nov 15, 2013 at 2:54 AM
The reason why I ask is because I have my three lists set up that I use for my cascading. The first two lists are the same are the same regardless of the content type. However, the values that should be available in the 3rd drop down should be filtered based on the Content Type selected.

Data structure in List 3. Based on the Content Type selected I want to use a CAML Query to only select the fields associated with that "FileType"
Title             SubSection                                      FileType
1.1.1 PR          1.1 Purchase Request Documentation              Contract
1.1.2 Property    1.1 Purchase Request Documentation              Contract
1.1.3 AAP         1.1 Purchase Request Documentation              Contract
1.1.1 ABC         1.1 Purchase Request Documentation              DeliveryOrder
1.1.2 DEF         1.1 Purchase Request Documentation              DeliveryOrder
1.1.3 GHI         1.1 Purchase Request Documentation              DeliveryOrder
So the scenerio would be that I already have a document set created. I go to "Upload" document. When I upload the document, I'm eventually brought to the metadata form. This is where I have implemented the Cascading Dropdown menus. However, the last requirement is to filter the last list based on the content type selected. Below are how examples of how the data would be represented if I could get the filter to work correctly on the last dropdown menu.

Example 1:
Content Type:  Contract
Drop Down 1:  1. Pre-Solicitation
Drop Down 2:  1.1 Purchase Request Documentation
Drop Down 3:  1.1.1 PR
              1.1.2 Property 
              1.1.3 AAP
Example 2:
Content Type:  Delivery Order
Drop Down 1:  1. Pre-Solicitation
Drop Down 2:  1.1 Purchase Request Documentation
Drop Down 3:  1.1.1 ABC
              1.1.2 DEF
              1.1.3 GHI
So I need to figure out how to get the Content Type from the dropdown menu on the EditForm.aspx. As I mentioned above, I've tried to use the jQuery and Javascript, but my syntax must be incorrect.

Does this make sense of what I'm attempting to accomplish?
Coordinator
Nov 15, 2013 at 4:57 AM
Got it.

The Content Type is displayed in a select, not an input element. Try this:
var strContentType = $("select[title$='Content Type']").val();
alert("Content Type: " + strContentType);
You should get good at looking into the DOM with a DOM inspector like Firebug.

M.