I am using Rails MVC project. I have a javascript function defined as follows in assets/application.js
function getBiobank(){
var biobank = document.getElementById('biobank');
var cohort = document.getElementById('cohort');
var biobank_selectedValue = biobank.options[biobank.selectedIndex].value;
if (biobank_selectedValue == 'Healthcare Embedded Biobanking' || biobank_selectedValue == 'BMB-CCC' || biobank_selectedValue == 'UKSH Clinic Consent' || biobank_selectedValue == 'BMB-GYN' ){
cohort.options.length = 0;
cohort.options[0] = new Option('--Select Cohort',' ')
}
}
And in my view, _form.html.haml file I have the following
%h3 Basic
.form-group{class: ("has-error" if @transfer_request.errors.has_key?("Access requested to"))}
= f.label "Access requested to", class: "control-label"
%br
Biomaterial #{f.check_box :access_biomaterial}
Data #{f.check_box :access_data}
= f.error "Access requested to"
= f.input :project_title
= javascript_include_tag "application", "data-turbolinks-track" => true
= f.input :biobank, collection: TransferRequest.biobanks.keys, prompt: 'Select biobank', :input_html => {:onclick => "getBiobank()", :class => "stext"}
When I start the server and check click the drop down list, I get the error in browser console as follows
Uncaught ReferenceError: getBiobank is not defined at HTMLSelectElement.onclick
Is this a scoping issue?. Any hints would be helpful. Thanks!