It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

javascript not working in chrome

Bryan Tay Jul 14, 2013

Hi,

I've created 2 custom fields with following code:

<script type="text/javascript">
var source = document.getElementById("customfield_00001");
var dest = document.getElementById("customfield_00002");

source.onchange = function()
{
var selectedText = source.options[source.selectedIndex].text;
if (selectedText == 'option1') {dest.value = 'Destination';}
else {dest.value = 'option2';}

alert(source.options[source.selectedIndex].text);
};
</script>

Check that it works on IE 8 and Firefo (V12) most of the time.

If I change project (first field on the screen), the java script does not work sometimes.

Need to know:

1. What is the proper way to write java script that compatible to chrome, ie and firefox?

2. Tried some of the jquery options found on the internet and it doesn't seems working.

3. Not sure why it doesn't work on chrome (v28).

I'm using JIRA Version (v6.0#6095-sha1:601557e)

Thanks in advance.

3 answers

1 accepted

1 vote
Answer accepted
Rambanam Prasad Jul 14, 2013

try with following code

<script type="text/javascript">
jQuery(document).ready( function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {
    callJSFunction();
});
callJSFunction();
function callJSFunction(){
   var source = document.getElementById("customfield_00001");
var dest = document.getElementById("customfield_00002");

source.onchange = function()
{
var selectedText = source.options[source.selectedIndex].text;
if (selectedText == 'option1') {
dest.value = 'Destination';
}
else {
dest.value = 'option2';
}

alert(source.options[source.selectedIndex].text);
};
 
}
});
 
</script>


and also check the following post
https://answers.atlassian.com/questions/47843/strange-javascript-problem-in-create-screen

Bryan Tay Jul 15, 2013

Thanks Rambanan. Ur scripts works well.

0 votes
Dipti Ranjan Behera Jul 14, 2013

@Bryan,

Please put more effort on the jquery option as this is the best solution (AJS framework from Jira).

Doing through Javascript is not the right thing.

some example : http://www.j-tricks.com/1/post/2012/02/some-ajs-tricks.html

https://answers.atlassian.com/questions/169529/jira-6-0-javascript

0 votes
Boris Georgiev Jul 14, 2013

I think it will help if you post any errors from the Chrome console along with the question.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

9,987 views 46 44
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you