I'm trying to show the selected option on a select input type in an HTML form.
This is my input type:
<div id="selectorTemaMensaje" class="form-group"><label> Motivo del mensaje: </label>
<select onchange="return opcionesMensaje();" required class="form-control" name="tema">
<option> </option>
<option data-tema="material" >Tengo problemas para acceder al material del curso</option>
<option data-tema="notaExamen" >Tengo problemas con la nota recibida en un examen</option>
<option data-tema="envioPago" >Quiero avisar de un pago que hice o saber si estoy debiendo alguna cuota</option>
<option data-tema="envioDoc" >Tengo problemas relacionados con el envío de la documentación solicitada</option>
<option data-tema="certificado" >Quiero saber cómo obtener mi certificado</option>
<option data-tema="docente" >Quiero preguntar a un docente por una duda con el material de una bolilla</option>
<option data-tema="otro" >Otro</option>
</select>
</div>
<span id="mostrar"></span>
This is my JS:
$(document).ready(function(){
function opcionesMensaje() {
var sel = document.getElementById('select');
var mostrar = document.getElementById('mostrar');
sel.onchange = function(){
var selected = sel.options[sel.selectedIndex];
mostrar.innerHTML = selected.getAttribute('data-tema');
};
sel.onchange();
}
}
I keep getting
Uncaught ReferenceError: opcionesMensaje is not defined
Every time I try to select an option.
The JS is inside a file that is called at the footer. I can see that file when looking into the page source. And the jQuery file is called before mine.