Execute javascript code on page load

Hi
I am currently customizing a SugarCRM instance. In one module I have created a few custom fields and a drop down menu. Based on the selection of the drop down menu I want to show or hide some of my fields. This works fine. My question is about the initial load of the page: In that case, all possible fields are displayed - not only the ones that should be displayed based on the default selection in the drop down menu.

My first instinct was to register the onload event and just hide whatever I don’t need to see when the page is loaded. But I couldn’t find anywhere to place it as I don’t want to change /modules/… directly. I’d like to restrict my changes to /custom/modules…

Any ideas?

push

push

The best thing to do in such situations is to start out setting the “display: none;” CSS property for all the fields which are dependent on your dropdown value. You can then run a function “onChange” of the dropdown that checks for the dropdown value, then if the dropdown value fulfills the condition for display of your dependent field(s), the function does this for each dependent field:

document.getElementById("<YourDependentField>").style.display = "inherit";

Hope this helps!
AK

What i would do is to leave all fields over the edit view. On the file custom/modules/<module_name>/metadata/editviewdefs.php change the dropdown field

'displayParams' => 
            array (
              'field' => 
              array (
                'onchange' => 'display_fields(this);',
              ),
            ),

so when the value changes it will display/hide fields.

Don’t forget to add the .js file on the includes.