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

This widget could not be displayed.

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

This widget could not be displayed.

Hi Jamie,

Have changed the var status as below.

status = document.getElementById('customfield_10473');

Not sure whats wrong with the id's

This widget could not be displayed.

Hi

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

Can you please advise

This widget could not be displayed.

Which jira version are you using?

This widget could not be displayed.

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>

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published yesterday in Marketplace Apps

The 7 hacks of highly successful automation

...there's anything I've learnt from working, it's that people are lazy! No offense to anyone reading this, but it's true and we can all admit it. The easier you make something for someone, the more...

81 views 0 8
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