I am using a javascript function to populate a drop-down list based on the selection of another drop down however this is always setting the drop-down to the from focus despite me adding code to set the focus to another field. Could someone please help ?
function Form_onload() {
//Function to Filter SubPicklist
filterPicklist = function (oPicklist, oSubPicklist) {
Xrm.Page.getControl(/mx_problemsubcategories/).setFocus(false);
if (oSubPicklist.getAttribute().getSelectedOption() != null) {
var currentText = oSubPicklist.getAttribute().getSelectedOption().text;
var currentValue = oSubPicklist.getAttribute().getSelectedOption().value;
}
else {
var currentText = //;
var currentValue = 0;
}
if (!oSubPicklist.originalPicklistValues) {
oSubPicklist.originalPicklistValues = oSubPicklist.getAttribute().getOptions();
}
// Clear existing options
var lstLen = parseInt(oSubPicklist.originalPicklistValues.length);
for (var i = 0; i < lstLen; i++) {
oSubPicklist.removeOption(oSubPicklist.originalPicklistValues[i].value);
}
// Loop through original values and add back any that match the parent
if (oPicklist.getAttribute().getOptions() != null) {
for (var i = 0; i < lstLen; i++) {
var origOpt = oSubPicklist.originalPicklistValues[i];
var startVal = oPicklist.getAttribute().getValue() * 100;
var endVal = (oPicklist.getAttribute().getValue() * 100) + 99;
if (parseInt(origOpt.value) >= startVal && origOpt.value <= endVal) {
oSubPicklist.addOption(origOpt);
}
}
}
// put back original value
try {
oSubPicklist.getAttribute().setValue(currentValue);
//Xrm.Page.getControl(/subject/).setFocus(true);
Xrm.Page.getControl(/mx_problemsubcategories/).setFocus(false);
}
catch (e) {
alert(/ERROR fn filterPicklist: / + e.InnerException.toString);
}
Xrm.Page.getControl(/mx_problemsubcategories/).setFocus(false);
//Xrm.Page.getControl(/subject/).setFocus(true);
} // endfn filterPicklist
var oPicklist = Xrm.Page.getControl(/mx_problemcategories/);
var oSubPicklist = Xrm.Page.getControl(/mx_problemsubcategories/);
filterPicklist(oPicklist, oSubPicklist);
//Xrm.Page.getControl(/subject/).setFocus(true);
Xrm.Page.getControl(/mx_problemsubcategories/).setFocus(false);
}
function mx_problemcategories_onchange() {
var oPicklist = Xrm.Page.getControl(/mx_problemcategories/);
var oSubPicklist = Xrm.Page.getControl(/mx_problemsubcategories/);
filterPicklist(oPicklist, oSubPicklist);
} //endfn mx_keyword_primary_onchange