I'm not sure what is going with your code, but it appears to be related to FireOnChange being called from OnLoad.
I've had good luck by creating a function OnLoad and calling that function wherever I want to update the field visibility.
Add this code to OnLoad:
document.HideElement = function(element) {
if (element == null)
return;
element.style.visibility = 'hidden';
}
document.HideField = function(field) {
var hidden = document.getElementById(field);
if (hidden != null)
document.HideElement(hidden);
hidden = document.getElementById(field + "_c");
if (hidden != null)
document.HideElement(hidden);
hidden = document.getElementById(field + "_d");
if (hidden != null)
document.HideElement(hidden);
}
document.ShowElement = function(element) {
if (element == null)
return;
element.style.visibility = 'visible';
}
document.ShowField = function(field) {
var hidden = document.getElementById(field);
if (hidden != null)
document.ShowElement(hidden);
hidden = document.getElementById(field + "_c");
if (hidden != null)
document.ShowElement(hidden);
hidden = document.getElementById(field + "_d");
if (hidden != null)
document.ShowElement(hidden);
}
document.HandleFieldVisibility = function() {
if(crmForm.all.new_contacttype.DataValue == 2)
{
crmForm.all.parentcustomerid.DataValue = null;
crmForm.all.parentcustomerid.ForceSubmit = true;
document.HideField('parentcustomerid');
document.ShowField('new_partnerid');
}
else if(crmForm.all.new_contacttype.DataValue == 1) {
crmForm.all.new_partnerid.DataValue = null;
crmForm.all.new_partnerid.ForceSubmit = true;
document.HideField('new_partnerid');
document.ShowField('parentcustomerid');
}
}
// This actually calls the function
document.HandleFieldVisibility();
Add the same line of code to your on change event:
document.HandleFieldVisibility();
I hope this helps. Good luck!
-Andrew Zimmer