Create Issue Screen - Java script to include a logic for depending fields.

We are using Jira 4.4.5

We have a Radio button field in the "Create Issue Screen" named BCP with options 'Yes' and 'No'.

When the BCP is 'Yes' then another Text field 'Reason' has to be displayed.

When the BCP is 'No' then the other Text field 'Reason' should not be displayed.

I am able to achieve this using a java script in the description of the field 'BCP'.

However the issue is that we have another Radio button 'SP' with options 'Yes' and 'No'.

And the samething, when SP = Yes, another text field 'SPReason' should be displayed. If SP=No then 'SP Reason' should not be displayed.

When i tried to write the smilar java script for the field 'SP' it is not working.

Cant we have two java scripts for two different fields in the same Create Issue page.

Please let me know how can i have the logic work for both the field 'BCP' and 'SP'.

Note these fields are mandatory fields.

Below is the java script i have used for the fied 'BCP':

<script language="JavaScript" type="text/javascript">

BCPYes = document.getElementById("customfield_11305-1");

BCPNo = document.getElementById("customfield_11305-2");

try {

window.onload =function ()

{

document.getElementById("customfield_11306").parentNode.style.display="none";

Radiochanged();

};

function Radiochanged()

{

BCPYes.onclick= function ()

{

document.getElementById("customfield_11306").parentNode.style.display="";

};

BCPNo.onclick= function ()

{

document.getElementById("customfield_11306").parentNode.style.display="none";

};

};

}

catch (err) {}

</script>

A similar script when used for the field 'SP'. It is not working.

7 answers

1 accepted

Hi,

Having 2 functions on window.onload is not a problem,

You should understand the concept of how it works,

When a url is refreshed or loads for the first time, it will start to load, This is the point where it triggers the function, When it triggers, it will execute the condition that is inside.This is the working.

No matter how many window.onload you use.

The other may not work for you for several reasons,

like the field may not be there when the page get loads,

or your JS would have not reflected in the browser yet.

Calling the function here seems to be wrong for me

window.onload =function ()

{

document.getElementById("customfield_11306").parentNode.style.display="none";

Radiochanged();

};

Cause during onload of the page, user cannot change the radio buttons value, so here I will not appreciate,

Instead use it in onclick event,like this,

<script type = "text/javascript">
document.getElementById("customfield_xxxxx").onclick = function(){
document.getElementById("customfield_xxxxx").parentNode.style.display="";
}
</script>

Hope This Helps.

Hi,

Java script has a weird behaviour, You will not be able to see the change unless you refresh it or clearing your cache. Refresh your page well or clear the cache and give it a try once. It is not wrong to have 2 javascript in the create issue screen.Your first one works because it has been deployed some time back, this you have created newly, which will come once you refresh, set code like "alert("HI");" in your code to check whether your code works after refreshing or clearing the cache.

use some thing like this to check first,once you clear your cache,

BCPYes.onclick= function ()

{

alert("Yes");

};

BCPNo.onclick= function ()

{

alert("No");

};

Surely it'll work, so try.

Hope this helps.

Hi All,

Any update on this issue..

Any work around without using the plugins.

Can Any one help ?

I think that you have assigned two functions to the same event window.onload

Hi zezeto, Thanks for the response.

I think what you said is right. Both the functions are to the same event window.onload

Can i have both the pieces of code in one java script for one field's description in stead of 2 java scripts for 2 different fields?

Or how can have the other java script under another event? If yes, which event i need to put the java script.?

I do not know java scripting much, your help would be appreciated.

Thanks, Harish

Put this code in the latest field description.

<script language="JavaScript" type="text/javascript">

BCPYes = document.getElementById('customfield_11305_1'); BCPNo = document.getElementById('customfield_11305_2'); BCPReason = document.getElementById('customfield_11306FieldArea'); BCPReason.style.display='non'; SPYes = document.getElementById('customfield_11307_1'); SPPNo = document.getElementById('customfield_11307_2'); SPReason = document.getElementById('customfield_11308FieldArea'); SPReason.style.display='non'; if( BCPYes && BCPNo ){ BCPYes.onclick=function(){ BCPReason.style.display=''; } BCPNo.onclick=function(){ BCPReason.style.display='non'; } } if( SPYes && SPNo ){ SPYes.onclick=function(){ SPReason.style.display=''; } SPNo.onclick=function(){ SPReason.style.display='non'; } }
 </script>

Did you use fire bug when you write jscript code?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Posted 13 hours ago in Jira

We want to know what Jira Service Desk apps you're using!

Hi Community! My name is Amir and I’m on the Jira Service Desk product marketing team at Atlassian. Our team would love to understand how you’re leveraging our ecosystem for Jira Service Desk. Wha...

36 views 0 5
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