You could lend me a hand in the following, I'm working with ASP.NET MVC , to capture the text of the selected combo and put it to the model I use a hidden
, I have something like this:
$(function () {
$("#datosCombo").change(function () {
var selTypeText = $("#datosCombo option:selected").text();
$("#DatosComboDescripcion").val(selTypeText);
});
});
<select class="form-control" data-val="true" data-val-number="El campo debe ser un número." data-val-required="El campo es obligatorio." id="datosCombo" name="datosCombo">
<option value="5">100000211639</option>
<option value="6">200000211639</option>
<option value="7">300000211639</option>
<option value="8">400000211639</option>
</select>
<input id="datosComboDescripcion" name="datosComboDescripcion" type="hidden" value="100000211639">
Everything works correctly, every time I select an element of the combo my hidden variable updates its value (it's the goal).
The problem is this: If I have 10 combos I would have to have 10 Scripts and that does not seem very maintainable.
What I want to do is: Have a generic script that detects the event of any combo and assign it to a variable, so if I have 10 combos, all these combos will automatically get this function when their event is triggered and assign the hidden text.
Note. If it's any use the hidden
will always have the name of the combo plus description: "NombreCombo" + "Descripcion"