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 votes

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
Community showcase
Posted yesterday in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

23 views 0 2
View post

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