Wrap choice-field in multiple columns

Change log
October 19. 2014
Updated the code to get rid of a few wrong single quotes introduced when migrating this code from another server.

I received a comment on another post requesting a function to wrap the choice-field into any given number of columns. Say you have a choice-field of “Checkbox” or “Radio” type with 20 choices and want to arrange them in multiple columns like this:

Here we go:
Create a document library to hold your scripts (or a folder on the root created in SharePoint Designer). In this example i have made a document library with a relative URL of “/test/English/Javascript” (a subsite named “test” with a subsite named “English” with a document library named “Javascript”):

You find the sourcecode for “WrapChoiceField.js” below.

The jQuery-library is found here. The pictures and the sourcecode refers to jquery-1.3.2.min. If you download another version, be sure to update the script reference in the sourcecode.

Add a CEWP below the listform in NewForm and EditForm and add reference to the scripts like this:

Create the list-fields as normal:

Sourcecode for the file WrapChoiceField.js:

/* Wrap choice-field in multiple columns
* ----------------------------------------------------
* Author: Alexander Bautz
* alexander.bautz@gmail.com
* Version: 1.3
* LastMod: 19.10.2014
* ----------------------------------------------------
* Must include reference to jQuery
* ----------------------------------------------------
  wrapChoiceField("FieldInternalName of your field",number of columns to wrap it into);
* ----------------------------------------------------

var fields = init_fields_v2();
function wrapChoiceField(fin,breakAfter){
	var toFind, index, counter, table, fillIn, len;
	toFind = "td.ms-formbody";
		toFind = "td.ms-formbodysurvey";
		index = 0;
		counter = 0;
		table = $(fields[fin]).find(toFind+' table:first');
		fillIn = $(table).find("tr:last").find("input:text").length === 1;
		len = $(table).find("tr").length;
		$(table).prepend("<tr id='vertical_"+fin+"_"+index+"'></tr>");
			if(counter > 0 && counter%breakAfter === 0){				
				$("#vertical_"+fin+"_"+index).after("<tr id='vertical_"+fin+"_"+(index+1)+"'></tr>");
				index += 1;
			}else if((fillIn && i === (len-1)) || (fillIn && i === (len-2))){
				$("#vertical_"+fin+"_"+index).after("<tr><td valign='top' colspan='"+breakAfter+"'><table><tr id='vertical_"+fin+"_"+(index+1)+"'></tr></table></td></tr>");
				index += 1;
			counter += 1;
function init_fields_v2(){
	var res = {};
	var myMatch = $(this).html().match(/FieldName="(.+)"\s+FieldInternalName="(.+)"\s+FieldType="(.+)"\s+/);	
			// Display name
			var disp = myMatch[1];
			// FieldInternalName
			var fin = myMatch[2];
			// FieldType
			var type = myMatch[3];
				}else if($(this).find("div[id$='TextField_inplacerte']").length>0){
			// HTML Calc
			if(type==='SPFieldCalculated' && $(this).text().match(/(<([^>]+)>)/ig)!==null){
			// Build object
			res[fin] = this.parentNode;
	return res;

Save the sourcecode to a file named “WrapChoiceField.js”, and upload to your document library as shown above.
Be sure to get the file type correct – the file extension is .js

That’s it!

Customized form?
How to use these scripts in a customized form


93 thoughts on “Wrap choice-field in multiple columns”

  1. Very impressive. I think I found a bug. When I first implemented I got this http://8201.freesharepoint2007.com/SiteImages/Forms/DispForm.aspx?ID=42

    the formatting was off and both radio and checkboxes were in the title field area.

    I went back and removed the radio (wrapChoiceField(“Radio”,4);), still same issue.

    When I removed the check boxes (wrapChoiceField(“Checkboxes”,4);) it worked.

    I started with renaming the fields, but no change. Then I removed the default selection, so the checkbox would be blank, and it worked.

    So as long as there is no default value in the checkbox choice it’s okay.

    Great Job!

  2. Now, is there a way to combine this script and the cascading script so when I make a selection in the first field, maybe a radio selection, then only some of the check boxes appear. Think of an example like regions and countries. I want to select a region, but only show the availabel countries for that region.

    Again, great job

  3. Last post for the day. this new functionality does not have to be radio or check boxes, I am just looking for the last child in the cascade to have the ability to be multiple select. Checkboxes are just more userfriendly and easier to see.

  4. Did you remember to use the correct “FieldInternalName” of the field in the function call? https://spjsblog.com/general-tips/

    You get this behavior (all choices stacked in the topmost field) if the FieldInternalName is wrong.

    The displayName is not always the same as the FieldInternalname…

    About your other request – maybe possible, but then you would need some external list to maintain the relationship between the choices – like in the “Cascading dropdowns” function.

    I may look into this issue, but sadly there is not time for it right now.


  5. No worries on the new request. Just something I was playing with. Here is something I add this to have a select all function.

    when you add a choice option as “Select All” this option will trigger the event. I placed it after your jquery reference.

    // need reference to jquery
    function initJQuery(){
        $(".ms-RadioText[title='Select All'] :checkbox").css({border:"2px green solid"});   
        $(".ms-RadioText[title='Select All'] :checkbox").click(
                     var otherids = (this.id).substring(0, (this.id).length-2 );
                     $("input[id^='"+otherids+"']").attr( "checked" , (this.checked)?"checked":"" );
  6. Hi larry,
    Can you confirm that you have used the correct “FieldInternalName” of your choicefield?

    If so – what browser (name and version) do you use? I have tested with IE8 and Firefox 3.1.

    Nice addition for select all.

    I have no problems with a default value selected in either radio-fieldtype or checkbox-fieldtype.


  7. I did check the sourse and had the correct field name. I think the issue I had was the field name. First attempt I used “CheckBox”. When I renamed it I used your names and also deselected a default option. Browser was ie 7. I created several other forms with different names, no issue

  8. @Nancy, You do not change the FieldInternalName, this is given by SharePoint upon creation of the field. This script relies on the name to process the function. Once you identify your FieldInternalName you may replace this in the mentioned script

  9. Hi Nancy,
    You do not replace anything in the script – the variable FieldInternalName is passed to the script when you call it like this:

    Here i have a field with a FieldInternalName of “YourFieldsInternalName”, and i want to wrap the choices in 4 columns.


  10. If I do not have a script called jquery-1-3.2.min saved as well, will this not work?
    i am confused as to how to make this work. Please assume I am less experienced than most who are coming to your page. Sorry!

  11. Hi Nancy,
    Sorry for not pointing to where the jQuery-library is found – i have updated the post and added this section:
    The jQuery-library is found here: http://www.jquery.com. The pictures and the sourcecode refers to jquery-1.3.2.min. If you download another version, be sure to update the script reference in the sourcecode.


  12. Hi Alexander:
    I too am trying to install this on my NewForm, but I cannot get it to work.

    One of my Internal Field Names is “CGL”. I placed that name into the CEWP script like this for two columns:


    I removed the “wrapChoiceField(“CheckBoxes”,4);” thinking that Larry’s issue above might affect what I am trying to do.

    Also, just to be clear, I saved the “WrapChoiceField.js” in my JQuery library but I did not amend any of the code in that js file. Should I?

    Charlie Epes
    Buffalo, NY

  13. Hi,
    The sourcecode for the file “WrapChoiceField.js” was corrupted in the codeview. I have updated the post and moved the code to a txt-file on Google Docs.


  14. Hi Alexander:
    Uhhh… My company will not allow us to access Google Docs… could you send it to my Gmail?

    chasepes at gmail dot com


    Charlie Epes
    Buffalo, NY

  15. Hi all,

    I followed all steps, but it still doesn´t work.

    Let me ask you something, I have to change something in scripts?

    I have 2 scripts now (jquery-1.3.2.min.js / WrapChoiceField.js), it that right?


  16. @Adalba Calonego, review the steps again. there is something you missed. It is important that you use the FieldInternalName and the CEWP with the script and script links are after the list form. I have found several times once I reviewed the steps and redid it, it worked perfectly.

  17. I did it again, and still doesn’t work.
    …and I don’t know why!!!

    I created the CEWP and add the code in source Editor. The code has links to .js scripts… (jquery-1.3.2.min.js / WrapChoiceField.js).

    The “FieldInternalName” is ok. I took it in the source of page.

    Maybe is missing something, but I can’t find what. Can you help me?

    Thanks a lot.

  18. Hi,
    Try to add an alert in a new line in the CEWP – like this:


    Does it alert like this:
    function (E, F) {return new (o.fn.init)(E, F);}

    If not your reference to jQuery is not right – edit the src=””.


  19. thats the code in the CEWP. Is this right?


    I uploaded these .js files to a “Document Library”.
    Then I created a CEWP in the newform, after list form, and put above code.

    When I try to access this page, nothing happens…

    I did something wrong? Thanks for you patience…

  20. Like this (this is the code in the CEWP BELOW the list form webpart:

    <script type="text/javascript" src="/test/English/Javascript/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="/test/English/Javascript/WrapChoiceField.js"></script>
    <script type="text/javascript">
    // alert to test that the script is refered OK - should alert the full function
    // The actual function call
  21. When i put the alert above the function call, nothing happens…
    if I put it below, it get the number of columns… in your script it will return 5 for example.

    Everything looks fine, or it must returns some value?

  22. From your code it looks like you are calling the “wrapChoiceField” wrong:


    Remove the “=” like this:



  23. yeah, it’s wrong… i fix it, but still doesn’t work…


  24. Edit: The code was distorted – i placed it in a codeblock – Alexander

    <script type="text/javascript" src="https://saows1701.accenture.com/sites/portalcoe/JavaScript/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="https://saows1701.accenture.com/sites/portalcoe/JavaScript/WrapChoiceField.js"></script>
    <script type="text/javascript">
  25. It looked like you missed a closing script tag in the line calling the “wrapChoiceField”.

    Can you test the code i edited in your comment?

  26. I removed this closing tag… but I tested your code and doens’t work…


    In .js files I have to edit something? or I just upload both codes to a document library?

  27. You do not have to edit anything in the .js files.

    Try again the alert like i advised above (comment added October 6, 2009 at 10:27 pm).

    This alert should alert the full function from the file wrapChoiceField.js – if not it is something wrong with the file….


  28. Great work!

    working fine but only have one issue. If we have more than one page and have branching on each page it doesnt work right. it just moves every option to top of page inside area of first option.

    Any help much appreciated.

    Thanks in advance

  29. Alexander,

    I’ve gotten this to work with relative ease (learned that field names cannot have spaces) on regular list forms but as soon as I try to implement it with custom list forms it doesn’t work. Have you had any luck with implementing this with custom list forms.


  30. @Casey,
    several things you can check.
    The links to your scripts are correct. the webpart is placed on the page after the listform, near the bottom. a
    nd most importantly confirm your FieldInternalName(s)

  31. @Larry,
    I’ve confirmed everything. To confirm all syntax I removed my custom list form and reopened my default list form and that action alone made the script work on the non-customized form. If I add another non-custom form above the custom form, it also works on that. Through trial and error with custom and non-custom forms I can get it to work every time with the non-customized and never with the custom forms.

    Any help?

  32. @larry

    Yes – a custom list form generated in SPD by going to Insert –> SharePoint Controls –> Custom List Form.

    Even leaving the defaults of the form (before removing any columns), it doesn’t split into columns.

  33. This script was not originally designed for that. By using a Custom List Form you changed the form and layout so the script will require some tweaking. I will let Alexander eplain his script from here.

  34. Hi Casey,
    Sorry for late reply, but as mentioned already i have been in bed with the flu for a week…

    The answer is simple, but i will explain it so that you understand why it’s not working.

    This script relays in the function init_fields() to identify and “objectify” the form by it’s table rows (tr’s). What the function does is to find all the FieldInternalNames in the code by this “information-tag”:

    <!-- FieldName="This is the DisplayName"

    and then make an object which, when called with the FieldInternalName of a field, returns an object containing the table row containing that field (both formlabel and formtable). When you in line 45 address the field like this:


    You are requesting the object containing the field with the FieldInternalName that is the same as the one passed to the function as the attribute “FieldInternalName”.

    When you modify the list form, you loose the FieldInternalName and therefore the function init_fields() does not return anything.

    To address the fields on a custom form you have to find another way of addressing these fields and to “objectify” them in the same matter as the script init_fields(). Basically you could insert some kind of “identifyer-attribute” on the tr’s, or you can go with the DisplayName – only remember thet if you change the displayname – you have to update your script…

    To use the “DisplayName”, replace the init_fields() functin with this one:

    function init_fields_CustomForm(){
      var res = {};
      $("td.ms-formlabel h3.ms-standardheader").each(function(){
      var str = $.trim($(this).text().replace(/*/g,''));
    	  res[str] = $(this).parents('tr:first'); 
      return res;

    Let me know if it works.


  35. How can this be applied to a Survey. The survey are only the one column which if I remember the Narrow had a change to make this work. Here the survey is one column by default

  36. Hi Alexander:
    I am trying to combine two JQuerys into one CEWP: your WrapChoiceField and your DatePickerToday. My script looks like this:

    // Array of fields to add this function to
    var arrOfFields = [‘_x0031__x002d_Prospect_x0020_Cle’,’_x0032__x002d_App_x0020_Info_x00′,’_x0033__x002d_Apps_x0020_from_x0′,’_x0034__x002d_Marketer_x0020_Ass’];

    Whether I have the two features in one or CEWP’s, the “Today” date feature disappears. Can you help troubleshoot?


    Charlie Epes

    1. Hi,
      I tested this by adding a “wrapped choice column” to my “DatePickerToday-list”.

      The code looks like this:

      <script type="text/javascript" src="/test/English/Javascript/jquery-1.3.2.min.js"></script>
      <script type="text/javascript" src="/test/English/Javascript/DateFieldValueOnClick.js"></script>
      <script type="text/javascript" src="/test/english/Javascript/WrapChoiceField.js"></script>
      <script type="text/javascript">
      // Array of fields to add this function to
      var arrOfFields = ['dummy','MyDateColumn1','MyDateColumn2'];
      // Wrap choice column

      This works without any modification.

      Send me your code to look at if you do not get it right.


  37. My list has 4 separate multiple-checkbox fields where I want to wrap the checkboxes. Must I save 4 separate .js files to refer to and add 4 separate CEWPs to hold the references? Or can one script take care of all 4 instances?

    1. I know it does not specifically state this, but if you look at the images of the script reference you will see

      <script type="text/javascript" src="/test/English/Javascript/jquery-1.3.2.min.js"></script>
      <script type="text/javascript" src="/test/English/Javascript/WrapChoiceField.js"></script>
      <script type="text/javascript">
      wrapChoiceField("RadioButtons",6); // call this for each field
    2. Hi,
      The only thing you need to do is to add a separate call to the script for each of your choice columns from the CEWP.

      <script type="text/javascript" src="/test/English/Javascript/jquery-1.3.2.min.js"></script>
      <script type="text/javascript" src="/test/english/Javascript/WrapChoiceField.js"></script>
      <script type="text/javascript">
      // Wrap choice column

      Duplicate line 6 for all your columns.


    3. I have added additional lines to correspond to all my fields according to your example. However this is not working for me no matter what I try. I have placed the CEWP below the listform in both my newform and editforms.

      My internal field names are:

      In line 28 of your code example “Sourcecode for the file WrapChoiceField.js”, you have the following:
      function wrapChoiceField(FieldInternalName,cols){

      In my saved .js file, I have changed this to:
      function wrapChoiceField(“State”,4){

      is this correct? (I am understanding that this is the only place in the code where it is required to reference an actual internal field name.)

      However- regarding the additional fields for which I want this to apply, how will it work if in that original code only one internal field name is present (“State”)?

    4. There is no need to change the original script. the fieldinternalnames will be updated in the call like this:


      I would suggest updating the source script with the original script. and add what Alexander has demonstrated just above.

  38. I have modified the source script per Alexander’s tip above. My question is- in the original script, what value should I place in what corresponds to line 28 of the code example? His example shows:
    function wrapChoiceField(FieldInternalName,cols){

    1. if you are modifing line 28 you are not doing it correctly. You should not be modifying the WrapChoiceField.js file. You should only be linking to this file. The call to this script should have your fieldinternalname like this:


      and repeat this for every field you want to wrap

    2. OK. I have reverted my WrapChoiceField.js file to exactly as it appears above, and my source script (in the CEWP placed under the listform) as follows:


      Yet, this is not working. I am stumped.

    3. Your script links to jquery and the wrapChoiceField.js are correct? This has happened to me many time I was off on my path and this would fail. Also this CEWP needs to be Below the List Form.

    4. I tried to show the full CEWP script but it stripped out…. trying again:



      is the full script. Yes- it is below the listform.

    5. Looks like ti still stripped it out.

      Yes- the first 2 lines above the previous are the calls to jquery-1.3.2.min.js file and the wrapchoicefields.js file.

  39. Here is what appears in my CEWP:

    <script type="text/javascript" src="MyFilePath/WrapChoiceField.js"></script>
    <script type="text/javascript" src="MyFilePath/jquery-1.3.2.min.js"></script> 
    <script type="text/javascript">
    1. I see only one possible issue in the path.
      you have

      and you may need

      Usually when i get to this point I go to my script library, Right click on my script file and select “Copy Shortcut”.

      this is the path I use in my script. It is the only way to be 100% sure you have the correct path.

      Also are you using any other scripts on the page?
      Are you sure you have the FieldInternalName and not the DisplayName?

    2. My file paths all are copied as you state, i just left out that full URL for privacy. The full URL for each is actually more like this:

      <script type="text/javascript" src="http://portal.mysite.com/sites/subsite/Scripts/WrapChoiceField.js"></script>
      <script type="text/javascript" src="http://portal.mysite.com/sites/subsite/Scripts/jquery-1.3.2.min.js"></script>
    3. Had to check, sometime I miss the easy stuff because I make it harder than it is.

      Also are you using any other scripts on the page?
      Are you sure you have the FieldInternalName and not the DisplayName?

      How about trying to get one field, is this successful?

    4. -Not running any other scripts.
      -Field Internal name and Display name are the same for all so I feel OK on that.

      Tried to get one field (the “State” field) and that was not successful.

      My list is a Links list. Might that be a factor?

      About ready to give up.

    5. No that does not matter. I was able to replicate this in a Links list. I reveresed the order of my scripts, but it worked because I Used the FieldInternalName. I would suggest you confirm yours are correct

      <script type="text/javascript" src="/sites/globalmp/JavaScripts/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="/sites/globalmp/JavaScripts/WrapChoiceField.js"></script>
      <script type="text/javascript">
    6. Success! I reversed the order of hte call linesas you said. For whatever reason, the did the trick. I thought I tried that earlier but it works now. All 4 fields are now in columns as intended.

      I cannot thank you enough for the patience in helping me through this. I was despairing I had wasted half my day. You are the best!

  40. This script works good, but it behaves strangely when there is a lookup type field on the form. It causes the values in the lookup field to appear below the field. Any ideas why?

  41. Thanks for the rapid reply. Here is more detailed information for your reference:

    The values in a lookup field are not displayed in the correctly on the newform and editform pages. They appear below the lookup selction control instead of in line with it. (i.e. The lookup values in “FieldB” appear to be displayed on top of “FieldE”.)
    This display issue affects all content types in the list even if they do not use the wrapped choice fields. This is only a display issue. The form functionality is not otherwise impacted.

    Relevant information and specs:
    1) The list is a custom SharePoint list
    2) The list uses content types
    3) The Title field is hidden on the newform and editform pages for all content types.
    4) The Title field is valued using a workflow after the item is saved.
    5) I am using a customized masterpage with another jquery script loaded into it.
    6) The wrapChoiceField.js script is contained in a hidden CEWP on the newform and editform pages.
    7) Only 2 Fields, “FieldJ and FieldK” are wrapped and it works fine. “FieldInternalName” is identical to “FieldName”.
    8) The list/form layout is below:

    FieldA type=”People Picker – SPFieldUser”
    FieldB type=”Lookup List Field- SPFieldLookup”
    FieldC type=”Single Line Text Field – SPFieldText”
    FieldD type=”Checkbox (4 choiced Not Wrapped):
    FieldE type=”People Picker – SPFieldUser”
    FieldF type=”People Picker – SPFieldUser”
    FieldG type=”People Picker – SPFieldUserMulti”
    FieldH type=”Date Picker – SPFieldDateTime”
    FieldI type=”Date Picker – SPFieldDateTime”
    FieldJ type=”Checkbox – SPFieldMultiChoice” (25 choices Wrapped in 4 columns)
    FieldK type=”Checkbox – SPFieldMultiChoice” (14 choices wrapped in 4 columns)
    FieldL type=”Checkbox – SPFieldMultiChoice” (5 choices Not Wrapped):
    FieldM type=”Checkbox – SPFieldMultiChoice” (5 choices Not Wrapped Specify your own value enabled)
    FieldN type=”DropDownButton – SPFieldChoice” (Dropdown list with specify your own value radio option)
    FieldO type=”Multi-Line Rich Text – SPFieldNote” (Dropdown list with specify your own value radio option)

    Troubleshooting Notes:
    1) No changes were made to the wrpaChoiceField.js script.
    1) I tried eliminating the customized master page with the other embedded jquery scripts as the cause by reverting to a default master page free of any other jquery or javascripts. (no effect)
    2) I tried eliminated the hidden title field as the cause by adding back to content types. (no effect)
    3) I presume that the syntax, path to the scripts and Field Internal Names are correct since the script does wrap the intended fields properly. Any other time these were incorrect, the script would simply not work at all.

    The actual script call is shown below:


  42. Hi Alexander. I’ve just got this working and I’m very happy with it – thanks! Just a suggestion, but it might be an idea to put your tip regarding Custom List Forms in the main article. I didn’t realise at first that the original script was only for out-of-the box forms!

  43. Hi, thanks for this script it has been a massive help there does not seem to be an option for this anywhere on the web.

    Just a quick question, the other JS file you mention is now at version jquery-1.6.4.min.js I updated the file reference in the code and got it all to work (i.e. the checkboxes are now in multiple rows)
    However I do now get a dialogue box that appears and shows the user the script code. This can be dismissed by pressing the Ok button but it is still annoying. Have you got any pointers on how to get rid of this? Many thanks.

  44. Following the part on here about surveys and the current version 2 script from Feb 2012 I have some adjustments to your script I would like to propose.

    For the init function before it does anything;

    function init_fields_v2(){
    	var tdClassToFind = '.ms-formbody';
    	if ($("td.ms-formbodysurvey").length > 0) {
    		tdClassToFind = '.ms-formbodysurvey';

    Along with one line in getFieldValue function;

    		valRaw = $(fields[fin]).find(tdClassToFind).text();

    I tried entering the var tdClassToFind and if statement at the start of the script as you have done above but it only ever worked when I moved it into the init function for some reason.

  45. Hi Alex,

    I followed the instructions provided above right now to the letter and the choice values are still not working. Could it be that I am using jquery-1.7.2.min (which I referenced correctly) or might it be something that is blocked on my SharePoint site to not run js scripts – though I am positive that js scripts are used elsewhere.

    I am using SP2007.

    The thing is I don’t even get an error – it just doesn’t seem to do anything. Were there any updates to this one?

  46. I tried this code with my Sharepoint having a column Session Name with 20 possible choices and the checkbox still is in Vertical list alignment. Can you help me with detailed instructions?

  47. Hi – I have followed your instructions exactly, and I am not able to get the columns to display horizontally. I have checked that the FieldInternalName is correct. Do I need to modify any of the code on the “WrapChoiceField.js” file? I just need to input my specific InternalFieldName in the Javascript web part? Thanks in advance!

    1. Which version of SharePoint are you using? – if it is SP2007 or 2010 you must remember to put the CEWP below the form web part.

      If you are using SP2013 you can try wrapping the code like this:

           wrapChoiceField("FieldInternalName of your field",number of columns to wrap it into);


      1. I am using SP 2007 and I added the Content Editor Web Type with the below script (Used the FieldInternalName):


        Question I have is, do I need to modify any of the code within the two Javascript files themselves (jquery 1.3.2) (WrapChoice Field)? I wasn’t sure whether I needed to update the FieldInternalName within the WrapChoiceField function or leave it unmodified. Do I need a different version of jquery for this to work?

        One thing I should mention is that I believe this is setup in a Custom List as it was created as a “Custom List” within the Custom List category. Thanks…

Leave a Reply

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