Java script to display a custom field based on value of other field

Hi

I have the below java script to display a custom field based on other field.

<script type="text/javascript">
status = document.getElementById('customfield_10473FieldArea');
target = document.getElementById('customfield_10521FieldArea');
// Hide the target field by default
target.style.display = 'none';
status.onchange=function() {
alert(status.value);
if (this.value != "*Doesn't*") {
target.style.display = '';
} else {
target.style.display='none';
}
};
</script>

By default the custom field is hidden but not sure why the function onchange is not getting invoked and the custom field 10521 is not getting enabled on the value change.

6 answers

0 vote

The ids are wrong. The FieldArea itself will not change, just the input element within it.

Hi Jamie,

Have changed the var status as below.

status = document.getElementById('customfield_10473');

Not sure whats wrong with the id's

Hi

Have changed the id's but still doesn't seem to work.

Can you please advise

Which jira version are you using?

Which jira version are you using?

Hi Tom We are using 3.12

Also what i nticed was when i did view source the java script is in div tags.

Not sure if they need to be part of div tags

<input type="text"
name="customfield_10521
value=""
id="customfield_10521"
class="textfield"
/>

<div class="fieldDescription"><script type="text/javascript">
field = document.getElementById('customfield_10473');
if (field) {
target = document.getElementById('customfield_10521FieldArea');
// Hide the target field if field isn't "Yes"
if (field.value != '*Doesn’t*') target.style.display='none';
field.onchange=function() {
if (this.value != '*Doesn’t*') {
target.style.display = 'none';
} else {
target.style.display='';
}
}
}
</script></div>

what type of this filed , is it cascade or select ?

field = document.getElementById('customfield_10473');

also refer this http://confluence.atlassian.com/display/JIRACOM/Using+JavaScript+to+Set+Custom+Field+Values

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 yesterday in Marketplace Apps

Tips on how to choose the best estimation method for your planning

Planning and grooming sessions all come with their own sets of rules. Team members meet to estimate stories or other work items, all according to an agreed-upon process. And with every session comes ...

63 views 0 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