Convert text field to picklist in MS CRM

October 18, 2010 by  

This function below describes how you can convert a text field into a picklist.This original script was developed by MS CRM 4.0 – Unleashed. I made a few changes to it so you can now save a picklist value while displaying the text. If no text array is passed than the values will be shown.

gConvertTextToPickList=function (controlId, valuearray, textarray) {

 Description:   Funcion to convert a nvarchar (text) field into a picklist
 Calls:   AddPickListValues()
 Returns:   nothing
 Example:  var arrValues = ['1','2','3'];
    var arrText = ['One','Two','Three'];
    gConvertTextToPickList('<your_textfield>',arrValues, arrText);

 //Referance the Text field
 var textControl = document.getElementById( controlId );
 if (!textControl) {return;}

 if (!textarray || (valuearray.length != textarray.length)) {
  textarray = valuearray;

 //Create a new Picklist (SELECT) control
 var picklistControl = document.createElement( "SELECT" );
 //Copy the Text field properties to the picklist =;
 picklistControl.req = textControl.req;

 //Set Required Style,  add the picklist values 
 picklistControl.className = "ms-crm-SelectBox "; //"selectBox " v3.0
 AddPickListValues( picklistControl, valuearray, textarray);

 //load the picklist selected value from the text field (saved) datavalue
 picklistControl.value = textControl.DataValue;
 textControl.parentElement.appendChild( picklistControl );  //append the picklist to the document
 textControl.parentElement.removeChild( textControl );   //remove the text field , we don't need it anymore.

 function AddPickListValues(picklistControl, valuearray, textarray) {

  for( var i = 0 ; i < valuearray.length; i++ ){
   //Create a new Option
   var option = document.createElement( "OPTION" );
   option.value = option.innerText = valuearray[i];
   option.text = option.innerText = textarray[i];
   picklistControl.appendChild( option );       //Add the option to the picklist

Related Posts:
Convert a text field to a button on a form in MS CRM
Add a helper / lookup button to a text field


One Comment on Convert text field to picklist in MS CRM

    Tyree on Thu, 10th Apr 2014 13:07

    Hello I am so grateful I found your website, I really found you by mistake, while
    I was looking on Bing for something else, Anyhow I am
    here now and would just like to say cheers for a incredible post and a all
    round entertaining blog (I also love the theme/design), I don’t have time to read through it all at
    the moment but I have saved it and also included your RSS
    feeds, so when I have time I will be back to
    read a great deal more, Please do keep up the superb jo.

    Feel free to visit my blog post how to build a gaming pc (Tyree)