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

Bharath Soni March 25, 2012

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
Ramesh Udari1 March 26, 2012

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

0 votes
Ramesh Udari1 March 26, 2012

Which jira version are you using?

Bharath Soni March 26, 2012

Hi Tom We are using 3.12

Bharath Soni March 26, 2012

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>

0 votes
Ramesh Udari1 March 26, 2012

Which jira version are you using?

0 votes
Bharath Soni March 26, 2012

Hi

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

Can you please advise

0 votes
Bharath Soni March 25, 2012

Hi Jamie,

Have changed the var status as below.

status = document.getElementById('customfield_10473');

Not sure whats wrong with the id's

0 votes
JamieA
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.
March 25, 2012

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

Suggest an answer

Log in or Sign up to answer