I am having an issue with Javascript when loading a page. I need to show or hide a section based on a fields value from a drop down. The sections are showing/hiding properly when the field is changed but does not run when the form loads. It is set to run OnLoad in the event handler in Form Properties. To be clear I want it to show/hide depending on the field when the page loads as well as when the field changes. Below is my code.
function showHide()
{
Xrm.Page.getAttribute("vent_marketinglistdivision").addOnChange(function(){
var vent_marketinglistdivision =Xrm.Page.getAttribute("vent_marketinglistdivision").getValue();
if(vent_marketinglistdivision == 693450003)
Xrm.Page.ui.tabs.get("tabAssociate").sections.get("VPIT").setVisible(true);
else
Xrm.Page.ui.tabs.get("tabAssociate").sections.get("VPIT").setVisible(false);
});
Xrm.Page.getAttribute("vent_marketinglistdivision").addOnChange(function(){
var vent_marketinglistdivision =Xrm.Page.getAttribute("vent_marketinglistdivision").getValue();
if(vent_marketinglistdivision == 693450005)
Xrm.Page.ui.tabs.get("tabAssociate").sections.get("VTST").setVisible(true);
else
Xrm.Page.ui.tabs.get("tabAssociate").sections.get("VTST").setVisible(false);
});
}