I need to make this code work so that if I contain the word in the url I switch to the default option as follows:
$('#servico').val(Sispostag.getParameterValue('servico'));
var url = location.href;
if(url.indexOf('undefined')==-1) {
$('#servico').val(Sispostag.getParameterValue('servico'));
var elementS = document.getElementById('servico');
elementS.dispatchEvent(new Event('change'));
} else {
$('#servico').val('123');
var elementS = '123';
elementS.dispatchEvent(new Event('change'));
}
But it always returns this error: Uncaught TypeError: elementS.dispatchEvent is not a function.
Can anyone help me solve this error?