jaspla
06-18-2012, 07:55 PM
Hello everyone. I'm new to JS, so please go easy on me! I'm working on a bit of code in MS Dynamics CRM. I built a form and copied code to generate a multi-select picklist from an option set. The code below does all of this beautifully, I just need to insert code to remove the last character--in this case, the last comma in a string. Can someone please tell me how to incorporate this into the code below? Thank you kindly for your help.
function OnLoad ()
{
// PL - the picklist attribute; PLV - used to save selected picklist values
var PL = crmForm.all.new_list; //CREATE NEW PICKLIST
var PLV = crmForm.all.new_text; //CREATE NEW TEXT FIELD TO STORE STRING
PL.style.display = "none"; //HIDES THE CONTROL
PLV.style.display = "none"; //HIDES THE CONTROL
// Create a DIV container
var addDiv = document.createElement("<div style='overflow-y:auto; height:135px; width:278px; border:1px #a1a5aa solid; background-color:#ffffff;' />");
PL.parentNode.appendChild(addDiv);
// Initialise checkbox controls
for( var i = 1; i < PL.options.length; i++ )
{
var pOption = PL.options[i];
if( !IsChecked1( pOption.text ) )
var addInput = document.createElement("<input type='checkbox' onclick='CallOnChangeEvent()' style='border:none; width:25px; align:left;' />" );
else
var addInput = document.createElement("<input type='checkbox' onclick='CallOnChangeEvent()' checked='checked' style='border:none; width:25px; align:left;' />" );
var addLabel = document.createElement( "<label />");
addLabel.innerText = pOption.text;
var addBr = document.createElement( "<br>"); //it's a 'br' flag
PL.nextSibling.appendChild(addInput);
PL.nextSibling.appendChild(addLabel);
PL.nextSibling.appendChild(addBr);
}
// Check if it is selected
function IsChecked( pText )
{
if(PLV.value != "")
{
var PLVT = PLV.value.split(", ");
for( var i = 0; i < PLVT.length; i++ )
{
if( PLVT[i] == pText )
return true;
}
}
return false;
}
}
function CallOnChangeEvent()
{
var PL = crmForm.all.new_list;
var PLV = crmForm.all.new_text;
PLV.value = "";
var getInput = PL.nextSibling.getElementsByTagName("input");
for( var i = 0; i < getInput.length; i++ )
{
if( getInput[i].checked)
{
PLV.value += getInput[i].nextSibling.innerText + ", ";
}
}
//MUST DO THIS TO TRIGGER A SAVE EVENT
var Name = Xrm.Page.data.entity.attributes.get("new_text");
Name.setValue(PLV.value);
}
function OnLoad ()
{
// PL - the picklist attribute; PLV - used to save selected picklist values
var PL = crmForm.all.new_list; //CREATE NEW PICKLIST
var PLV = crmForm.all.new_text; //CREATE NEW TEXT FIELD TO STORE STRING
PL.style.display = "none"; //HIDES THE CONTROL
PLV.style.display = "none"; //HIDES THE CONTROL
// Create a DIV container
var addDiv = document.createElement("<div style='overflow-y:auto; height:135px; width:278px; border:1px #a1a5aa solid; background-color:#ffffff;' />");
PL.parentNode.appendChild(addDiv);
// Initialise checkbox controls
for( var i = 1; i < PL.options.length; i++ )
{
var pOption = PL.options[i];
if( !IsChecked1( pOption.text ) )
var addInput = document.createElement("<input type='checkbox' onclick='CallOnChangeEvent()' style='border:none; width:25px; align:left;' />" );
else
var addInput = document.createElement("<input type='checkbox' onclick='CallOnChangeEvent()' checked='checked' style='border:none; width:25px; align:left;' />" );
var addLabel = document.createElement( "<label />");
addLabel.innerText = pOption.text;
var addBr = document.createElement( "<br>"); //it's a 'br' flag
PL.nextSibling.appendChild(addInput);
PL.nextSibling.appendChild(addLabel);
PL.nextSibling.appendChild(addBr);
}
// Check if it is selected
function IsChecked( pText )
{
if(PLV.value != "")
{
var PLVT = PLV.value.split(", ");
for( var i = 0; i < PLVT.length; i++ )
{
if( PLVT[i] == pText )
return true;
}
}
return false;
}
}
function CallOnChangeEvent()
{
var PL = crmForm.all.new_list;
var PLV = crmForm.all.new_text;
PLV.value = "";
var getInput = PL.nextSibling.getElementsByTagName("input");
for( var i = 0; i < getInput.length; i++ )
{
if( getInput[i].checked)
{
PLV.value += getInput[i].nextSibling.innerText + ", ";
}
}
//MUST DO THIS TO TRIGGER A SAVE EVENT
var Name = Xrm.Page.data.entity.attributes.get("new_text");
Name.setValue(PLV.value);
}