I do not achieve that when selecting an option that is not the first, the parameter is sent correctly to the function Export()
. The alert
I throw it correctly with the option that I select. But when sending the parameter, always send the first one.
Form:
var a = $("#paquetes option:selected" ).text();
$('#paquetes').on('change', function() {
alert( this.value );
var a = $("#paquetes option:selected" ).text();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="paquetes" class="selectpicker" onchange="">
<optgroup label="Seleccionar paquete a exportar">
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
</optgroup>
</select>
<button onclick="Export(a)" id="enviar" class="btn btn-success">Exportar a Excel</button>
All this is within a form.