I have this module naija passed to a template from the controller like this:
res.render('testing', {title:"filter setting page",
nigeria:naija
});
nigeria.states() generates the list of states in Nigeria into a select options successfully with this code:
select.form-select.col-xs-12.col-sm-12(id='selState1', onChange='listLgas(nigeria, this)')
each state in nigeria.states()
option(value='#{state}') #{state}
I want to use the selected state from the select element above to generate the list of local governments in another select when the onChange event of the select above triggers like this
select.form-select.col-xs-12.col-sm-12(id='selLga1')
script(type='text/javascript').
function listLgas(nigeria, element){
var selectedState;
console.log('inside setState')
element = this
var selectedOption = element.value
console.log(selectedOption );
lgas=nigeria.lgas(selectedOption )
console.log(lgas)
selLga1 = document.getElementById('selLga1')
selLga1.innerHTML =''
lgas.forEach(function(lg){
selLga1.add(new Option(lg,lg));
})
}
The problem is, I get 'nigeria is not defined' from onChange='setState(nigeria, this)'
I changed the event listener to onChange= 'listLgas(this)'
, hoping nigeria should be available globally in the template. This time i get 'nigeiria is not defined' in listLgass().
How do I make nigeria available to use in the event handler?