javascript for field behaviour

Hi, I tried adding the a script in the 'description' of my custom field (which is a dropdown). I edited the field configuration for the custom field.

When I create an issue and change the value of the custom dropdown, I dont get to see the alert that I added. Am I missing something?

The script I used is:

<script type="text/javascript">
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
callChangeFunction();
});
callChangeFunction();
function callChangeFunction(){
showHidField();
// dropdown custom field change function
$("#customfield_10300").change(function() {
showHidField();
});

}
function showHidField(){
//drop down field selected value
var dropDownFieldval = $.trim($("#customfield_10300 :selected").text());
alert(dropDownFieldval);
if(dropDownFieldval == 'MAS'){
alert('hello');

}
});

</script>

3 answers

1 accepted

you did't closed second function, try with this script by opening create screen in new tab(right click on create issue button and click on open link in new tab), if it is working in this page and not working in popup then load it as webresource module in plugin as @Bharadwajsaid

&lt;script type="text/javascript"&gt;
jQuery(document).ready(function($) { 
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { 
	callChangeFunction();
});
	callChangeFunction();
function callChangeFunction(){
		showHidField();
	// dropdown custom field change function
	$("#customfield_10300").change(function() {
		showHidField();
	});

}
function showHidField(){
	//drop down field selected value 
	var dropDownFieldval = $.trim($("#customfield_10300 :selected").text());
		alert(dropDownFieldval); 
	if(dropDownFieldval == 'MAS'){ 
		alert('hello');
	} 
}
});

&lt;/script&gt;

Thank you all. I want to set the value of a second dropdown depending on value selected in first dropdown. I could'nt get it to work and hence tried alert to check my first dropdown's value selected.

After using the script above, I resolved my problem. Thanks again.

I am seeking to do same thing. I need to fetch elements, which are added to the document when a list box is used. For some reason JIRA.Events.NEW_CONTENT_ADDED is not triggered for me when i use a list-box. Instead it triggers just one time when the create issue dialog opens. (because the dialog adds content it triggers the change event, so the event itself is working). AJS.$(document).ready(function() { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { alert('more content added'); }); }); using a listbox on create-issue dialog does not trigger the alert.

where you added your script? if you want to trigger on change event for list box then you need use same code as i specified in my answer!

There is no event fired for me when i use list box with the code above. I am sure the script is on page and active. It is actually triggered when pop up dialog appears. But then it remains quite. Even though, more content is being added to the DOM when i use listbox and it populates its options. my script is registered as webresource in atlassian-plugin.xml

is it going to second alert if you select MAS in dropdown?

you simply put dropDownFieldval in quotes and try.

Also you can refer this document from prasad https://answers.atlassian.com/questions/217176/show-hide-custom-field-depend-on-another-custom-field-value

0 votes
Mizan Community Champion Dec 15, 2013

What is the real task your script should do ?

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot