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

Harish January 14, 2013

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

1 vote
Answer accepted
Nitram
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.
January 15, 2013

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.

1 vote
Nitram
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.
January 15, 2013

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.

0 votes
Nadir MEZIANI
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.
January 15, 2013
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?

0 votes
Harish January 15, 2013

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

0 votes
Nadir MEZIANI
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.
January 15, 2013

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

0 votes
Harish January 15, 2013

Can Any one help ?

0 votes
Harish January 15, 2013

Hi All,

Any update on this issue..

Any work around without using the plugins.

Suggest an answer

Log in or Sign up to answer