How to change whether an attribute is mandatory depending on what the user selects in a dropdown


Users select from a dropdown list attribute when adding or editing metadata for an asset. Depending on what they select, the next attribute should be mandatory or not.


Users can select 'Yes' or 'No' from a dropdown attribute called 'Usage Restrictions Apply'. If they select 'Yes', the next attribute (a text area called 'Restriction Notes') must be filled in. If they select 'No' from the dropdown they do not have to enter anything.


Asset Bank does not support dependencies between attributes, except by using JavaScript


The solution is to make both the attributes mandatory, and then to use JavaScript in the dropdown attribute's onchange field to put a value 'N/A' into the text area if 'No' is selected by the user.

- Click 'Edit' next to the dropdown attribute in Admin->Attributes.

- Enter JavaScript into the 'onchange' field. Below is some example JavaScript that fits the above example. Note that the text area attribute in this example has an id of 706 (so has the id 'field706') , and the dropdown attribute value ID for 'Yes' is 20 and for 'No' is 21. You will need to substitute in your IDs accordingly.

if (this.value=='21' && document.getElementById('field706').value=='')
else if (this.value=='20' && document.getElementById('field706').value=='N/A')

Was this article helpful?

Yes No

Thanks for your feedback!