Need to hide/show a textfield based on the value of the check box using Javascript?

Hey guys,

Got a little problem/question:

I tried to implement the script from https://answers.atlassian.com/questions/158035/need-to-hide-show-a-textfield-based-on-the-value-of-the-check-box-using-javascript, but it doesn't seem to be working for me.

I've got the following fields:

Forward Email (customfield_13428) - Multicheckbox (Yes is selectedvalue=13924)

Email to forward to (customfield_13429) - Text Field < 255 char

Unsure what I'm doing wrong here?

<script type="text/javascript">
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
callHideShowFunction();
});
callHideShowFunction();
function callHideShowFunction(){
showHideReason();
$("#customfield_13428").closest('div.field-group').hide();
$('input:radio[name=customfield_13924]').click(function() {
showHideReason();
});
//the following event will work on only create screen
$('#create-issue-submit, #issue-create-submit').click(function() {
var emergencyImpl=$('input[name=customfield_13924]:checked + label').text();
var reasonValue=$("#customfield_13428").val();
if( emergencyImpl =='Yes' && ( reasonValue == '' || reasonValue == ' ') ){
alert("Please enter Reason");
return false;
}
});


}
function showHideReason(){
var emergencyImpl=$('input[name=customfield_13924]:checked + label').text();
if( emergencyImpl == "Yes" ){
$("#customfield_13924").closest('div.field-group').show();
}else {
$('#customfield_13428').val('');
$("#customfield_13428").closest('div.field-group').hide();
}

}
});
</script>

Any help would be fantastic.

Thank you!

2 answers

for check boxes you have to use the check box id to get value

var fieldusedforchage = document.getElementById('customfield_13924-1')

if(fieldusedforchage .checked)

{

field.style.display ='';

}

try with this script

&lt;script type="text/javascript"&gt;  
jQuery(document).ready(function($) {
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
        checkBoxFunction();
    });
    checkBoxFunction();
     
function checkBoxFunction(){                
            showorhidefields(); 
            //assume 4 checkbox there with name  'customfield_11705'
        $("#customfield_11705-1,#customfield_11705-2").click(function() {
            showorhidefields(); 
        }); 
     
         
    }
function showorhidefields(){
    alert("inside function");
    var checkedCheckboxes = $("input:checkbox[name=customfield_11705]:checked");        
            $("#customfield_11704").closest('div.field-group').hide();      
        checkedCheckboxes.each(function () {
                var selVal=$(this).next("label").text();
                alert("selVal: "+selVal);               
                if(selVal == 'Yes'){                    
                    $("#customfield_11704").closest('div.field-group').show();  
                }else {
                    $('#customfield_11704').val('');
                    $("#customfield_11704").closest('div.field-group').hide();
                }               
                 
            });
        }   
         
 
    });
&lt;/script&gt;

for refernce check this

https://answers.atlassian.com/questions/158035/need-to-hide-show-a-textfield-based-on-the-value-of-the-check-box-using-javascript

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot