views:

3154

answers:

3

Javascript

I have code that will hide various sections in a MS CRM form based on the value of a Picklist. The code executes in the onChange event of the Picklist. It hides the section by referencing a field in the section and then navigating up the DOM using the ParentElement syntax, as such:

crmForm.all.fieldName.parentElement.parentElement.parentElement.style.display = 'none';

This seems to work, with 1 exception. The offending section has a single read-only field, which I assume is the cause. No error is thrown. I've also tried variations with 2 and 4 ".parentElement" blocks.

How can I hide this section?

A: 

Sorry, buy can you clean up the question? You say it works with 1 exception when the section has a read-only field. Is that the field you are trying to work with in your example? Or can you work with any field in the section, but if there is one read only in the section it fails? What is the exception (doesn't work, javascript error)?

Robert MacLean
+1  A: 

Take a look at the following post. it uses section position instead of parentElement. http://mscrm4ever.blogspot.com/2008/08/show-hide-crm-form-section.html

A: 

The previous suggestion of hiding by section # will work. Or you could also try using fieldname_c instead of fieldname (and should only need 2 parentElements). _c is the "comment" (label) for the field and should be a bit more consistent.

David Eison