JIRA - show / hide field via javascript conditions only working on one field

On issue Creation, using code like this against 3 fields - If disclosed field = yes, then show. It's only showing one field on the screen (the last one) w/ that code in it, it's not showing all 3 fields. Each field works fine on it's own to show, just not when they are all setup together... Any ideas how to correct? I need to apply similar to 6 additional fields too.... Thanks!

<script type="text/javascript">
  disclosed = document.getElementById('customfield_10009');
  if (disclosed) {
      target = document.getElementById('customfield_10006').parentNode;

      // Hide the target field if disclosed != yes
 if (disclosed.value != '10005') target.style.display='none';
  
      disclosed.onchange=function() {
          if (this.value == '10005') {             
                     target.style.display = '';  
                  } else {
                 target.style.display='none';
          }
      }
  }
 </script>

4 answers

1 accepted

try with this code

<script type="text/javascript">
jQuery(document).ready(function($) {
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {				
				callShowHideFunctions();
			});
				callShowHideFunctions();
			
function callShowHideFunctions(){
				showHidefields();
			$('#customfield_10009').change(function() {		
				showHidefields();
			});	
}				
		
	function showHidefields(){	
						$('#customfield_10006').closest('div.field-group').hide();				
					if($("#customfield_10009 option:selected").text() == 'Yes'){						
						$('#customfield_10006').closest('div.field-group').show();						
					}else{
						$('#customfield_10006').val('');
						$('#customfield_10006').closest('div.field-group').hide();
					}
		}	
			
	
});
</script>

This worked!! I changed the fields to be radio buttons so it looks cleaner as well. Thank you!

check this post you can find hide field on radio button on change and check box on change events

https://answers.atlassian.com/questions/158035/need-to-hide-show-a-textfield-based-on-the-value-of-the-check-box-using-javascript

what type of field is the "customfield_10009", i mean is it radio button, select list or check box?

10009 is a select list field

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

552 views 3 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you