Multiple default values in a column of type “Checkboxes”

I got this request from Larry:

choice – Multiple select, check boxes, is there a way to have multiple default values. I may want the same 3 items to always be selected. by default SP only allows one option. This field for 90% may need those 3 requests. Can it be done?


Add this code to a CEWP below the form in NewForm or EditForm: Alter the reference to jQuery as needed.

<script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
/* Multiple default values in a column of type "Checkboxes (allow multiple selections)"
 * Created by Alexander Bautz
 * alexander.bautz@gmail.com
 * https://spjsblog.com
 * v1.0
 * LastMod: 22.02.2010
 *	
 Sets the default value of a column of type "Checkboxes (allow multiple selections)",
 by passing the FieldInternalName of the SharePoint-field with an array of values to prefill.
*/
fields = init_fields();
// Define the array if values
var myArr = ['Choice 4','Choice 9'];
// Call the function with the FieldInternalName of the field and the array.
setMultiSelectDefaultValues('MyMultiChoice',myArr);

function setMultiSelectDefaultValues(FieldInternalName,arrOfValues){
	$(fields[FieldInternalName]).find('input:checkbox').each(function(){
		var thisText = $(this).next().text();
		if($.inArray(thisText,arrOfValues)>-1){
			$(this).attr('checked',true);
		}
	});
}

function init_fields(){
  var res = {};
  $("td.ms-formbody").each(function(){
	  if($(this).html().indexOf('FieldInternalName="')<0) return;	
	  var start = $(this).html().indexOf('FieldInternalName="')+19;
	  var stopp = $(this).html().indexOf('FieldType="')-7; 
	  var nm = $(this).html().substring(start,stopp);
	  res[nm] = this.parentNode;
  });
  return res;
}
</script>

You also might want to take a look at this one:
Limit number of allowed selections in Checkboxes choice

Regards
Alexander

5 thoughts on “Multiple default values in a column of type “Checkboxes””

  1. I added a small addition, If you start with default selected items, there is no way to get back to that. Is it needed? probably not but if any one is interested I will post the code that resets checked items

Leave a Reply

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