Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Products
  • Jira
  • Questions
  • why the below code not working to show text field when YES radio button is clicked amongst YES/NO/NONE (by default) options

why the below code not working to show text field when YES radio button is clicked amongst YES/NO/NONE (by default) options

navneet nischal January 22, 2012

<script type="text/javascript">
var field = document.getElementById('customfield_10106');
if (field)
{
target = document.getElementById('customfield_10107').parentNode;
if (field.value != 'yes')
target.style.display='none';
field.onchange=function()
{
if (this.value == 'yes')
target.style.display = '';
}
}
</script>

5 answers

0 votes
Ron K January 24, 2012

JIRA supports jQuery. Try this code. Customfield_10000 is the radio button. Customfield_10001 is the text field. The value of “Yes” = 10000. Your value could be different.

<script type="text/javascript">

jQuery(function($){

$(document).ready(function(){


var currentValue = $('input:radio[name=customfield_10000]:checked').val();

if(currentValue == "10000") //The value in JIRA is numeric

$("#customfield_10001").parent("div").show();

else

$("#customfield_10001").parent("div").hide();


$('input:radio[name=customfield_10000]').click(function(){

var checkedValue = $('input:radio[name=customfield_10000]:checked').val();

if(checkedValue == "10000")

$("#customfield_10001").parent("div").show();

else {

$("#customfield_10001").val(""); //remove the value of the text field so it does not show

$("#customfield_10001").parent("div").hide();}

});

});

});

</script>

navneet nischal January 24, 2012

thanks RON, thank you so much, i will right away check the code..............no my target is to get plug-in for velocity field and embed javascript into it. do u have any idea regarding this?

navneet nischal January 24, 2012

because i was writing my code into another text field named TEST, but it appears on screen, so i need velocity field so that javascript could be written in der and it will not appear on screen............

thanks in advance

Ron K January 24, 2012

Yes, you can use the “Message Custom Field (for edit)” from the Atlassian JIRA Toolkit Plug-in. The “Velocity processed Message Custom Field” is not needed for simple JavaScript. However, you can also paste the code in the description of the custom field. This is usually easier. I have done both.

Note: If your project has a Field Configuration, the description of the custom field in the field configuration overrides the description set in the custom field. Therefore, you should add the code to the description of the custom field in the field configuration.

0 votes
navneet nischal January 23, 2012

hiiiiii

i am using jira 4.4.4

please sujjest me with answer since i am eagerly waiting for ur response.

0 votes
RambanamP
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.
January 23, 2012

Let me know the which version of Jira ur using

0 votes
Jeremy Largman
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 22, 2012

It's a bit hard to troubleshoot this without your custom fields installed. There's a bunch of discussion and comments on Displaying a Custom Field base on another field's selection. Have a look there.

navneet nischal January 23, 2012

thanks JEREMY but i dint get u. what do u mean by without the custom field installed. i am trying on a simple screen which has radio button,textfield and lastly again the text field on which javascript is written. i am able to hide the first textfield but i need it to reappear when radio button is clicked on YES.

navneet nischal January 23, 2012

<script language="javascript" type="text/javascript">
source = document.getElementById('customfield_10106-1');
target = document.getElementById('customfield_10107').parentNode;

var noneFormField = document.getElementById ('cf-customfield_10106');
if (noneFormField)
{ var parentDiv = noneFormField.parentNode;
parentDiv.style.display="none"; }


window.onload = function(){
validatedisplay();
}


if(source != null){
source.onchange=function() {
validate();
}
}


function validatedisplay(){
target.style.display = 'none';
}

function validate(){
if(source.value="10107"){
target.style.display = '';
}
else
target.style.display = 'none';
}
</script>

above code works well but when user clicks second time the text field doesnt hide.

please sujjest me what do i do. i am using jira 4.4

Jeremy Largman
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 24, 2012

I mean I don't have the specific custom fields you do, so I can't easily try. What are customfield_10106 and customfield_10107?

Try this:

  1. View the source for the page, with both custom fields. Notice both the id for each field, and the value.
  2. In your custom field, print out various statements along the way to debug. Like this:
    document.write(field.value);

That would write out the value of the field. Then you can get the comparison statements right.

0 votes
navneet nischal January 22, 2012

can u plz ping me on my mail navneetnischal367@gmail.com

Suggest an answer

Log in or Sign up to answer