Change content type with Jquery

I have a library with  four content types depending on what type of documents I upload.  I am looking to change the content type with Jquery.    The issue is I set jQuery to change the value of the "select" and I can get the value to change but it is not actually changing the content type as the fields are still the same.

This is how I am changing the value of the field

$("select[title='Content Type']").val("0x0101003738B6836D74264DA086725E379B1E3B010100204E39634D29E94683322CBA54BC8E15");

Please let me know if you have a solution for this.

Thank you

February 16th, 2015 6:33pm

Hi,

From your description, I am not quite sure that if you want to set a particular content type as the default content type  in content type field dropdown with jQuery.

If you want to change the default content type in the library. You could change the default content type with OOTB method by these steps:

  1. Enter your document library.
  2. Click Library Settings in the Ribbon.
  3. Click link Change new button order and default content type under Content Types section.
  4. Chang the order in the new page, and the first content type will be the default content type.

If I misunderstood above, could you please provide a screenshot for your requirement.

Best Regards
Free Windows Admin Tool Kit Click here and download it now
February 25th, 2015 8:15am

I am not looking to change the default content type. I am looking to change the content type using jquery in the upload/edit form.

Here is what I am doing now.  I am using cookies to store values for the upload form.  I am storing things like expense type (travel, training, Miscellaneous), title, description and a few other things.  Each expense type is a content type in my library as depending on the receipt that I upload I need to type in the specific information. 

When they upload a receipt I want it to select the correct content type from the dropdown using jquery (and the cookie).    I can get everything to work but when jquery sets the content  type dropdown the form does not reload with the correct content type it only changes the display value of the content type dropdown.

March 5th, 2015 7:38am

Hi,

You could try this code below:

<script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function(){

var b="0"+window.name;

if(b.length<=1){

$("select[title='Content Type']").val("0x0101003D746F2805C4974FA3FF6718C73037A200ECF66108DA30F947A519FE431E480B05");

$("select[title='Content Type']").change(); 

 window.name=window.name+11;

}else{return;}



})

</script>

Best Regards, Vincent Han
Free Windows Admin Tool Kit Click here and download it now
March 6th, 2015 11:35pm

Hi Phillip,

Any update?

Best Regards,

Dennis Guo

March 9th, 2015 8:51pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics