function conditional_text_input(choice_input_selector, checked_value, input_selector) { const input_form_group_el = $(input_selector).parents('div.form-group') const checked_option_el = $(`input[value="${checked_value}"]`) input_form_group_el.insertAfter(checked_option_el.parents('label')) input_form_group_el.hide() $(choice_input_selector).change(function() { if (this.checked && this.value == checked_value) { input_form_group_el.show(200) } else if (this.value != checked_value) { input_form_group_el.hide(200) } }) }