window.addEventListener("load", function() { (function($) { $(function() { // mail section var selectField_addrOther = $('#id_address'), data_addrOther_div = $('#id_other').parent().parent(), data_addrOther = $('#id_other'); console.log(data_addrOther, data_addrOther_div ); // make checked to get through the required function toggleVerified_addrOther(value) { if (value === "OTHER") { data_addrOther_div.show(); data_addrOther.val(""); } else { data_addrOther_div.hide(); data_addrOther.val("NONE"); } } // show/hide on load based on existing value of selectField toggleVerified_addrOther(selectField_addrOther.val()); // show/hide on change selectField_addrOther.change(function() { toggleVerified_addrOther($(this).val()); }); }); })(django.jQuery); });