Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with javascript to auto-hide custom fields based on another custom field value

Michael
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2020

Hello everyone,

I have 4 custom single select fields "Region", "Market A", "Market B", and "Market C".

I would like to hide the custom single select fields of "Market A", "Market B", and "Market C" based upon the value I select within the "Region" custom field. (I need to do this without any paid for plug-ins like script runner)

IE: If within "Region" I select the value of 'Region 1', I'd only like "Market A" to show up, and have the other Market custom fields be hidden.

Right now I'm trying to tweak a script I found within the atlassian documentation without any luck; and I believe I'm missing something since these are all custom fields and not a combo of custom and jira system fields.

Here is my coding so far:

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context) { console.log("new content added")

<script type="text/javascript">
region = document.getElementById('region');
if (region) {
target = document.getElementById('customfield_10200');
// Hide the target field if Region isn't "Market 1"
if (region.value != 1) target.style.display='none';

priority.onchange=function() {
if (this.value == 1) {
target.style.display = '';
target.value='Value 1';
} else {
target.style.display='none';
}
}
}
</script>

 

Any help would be greatly apperciated!

Thanks,

Michael

2 answers

1 accepted

0 votes
Answer accepted
Michael
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 11, 2020

Hi again everyone,

I was able to do this via Javascript within the description field of both the custom field itself as well as within the field configuration screen. I forgot to add some tweaked code to that screen; which made it not work.

Thanks,
~Mike

Alexey Osipov July 1, 2022

Hi Michael, @Michael would you mind to post your final working code?

Like stsci likes this
0 votes
kumar jira February 25, 2020

Hiding a field based on other field value can be done using Script runner behaviors.

Please let me know where you are writing this code.

Suggest an answer

Log in or Sign up to answer