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 vote
Mizan Community Champion Dec 15, 2013

What is the real task your script should do ?

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...

290 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