JQuery - Como cambiar atributos (max, min )de un input al seleccionar opciones en un select

 
Vista:
sin imagen de perfil

Como cambiar atributos (max, min )de un input al seleccionar opciones en un select

Publicado por Juan Casas (2 intervenciones) el 16/06/2023 19:38:33
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<div class="form-group">
                                            <label for="loan-interest"><b>SELECCIONE EL TIPO DE CRÉDITO</b>
                                                <small></small></label>
                                            <select class="form-select" name="loan-interest" id="loan-interest"
                                                placeholder="INGRESE EL MONTO DESEADO" class="input-item text-right"
                                                required>
                                                <option value="">SELECCIONE</option>
                                                <option value="27">ORDINARIO</option>
                                                <option value="18">CREDICONFIANZA</option>
                                                <option value="22.80">TEMPORADA</option>
                                                <option value="13.80">TU AUTO</option>
                                                <option value="11.40">TU CASA</option>
                                            </select>
                                        </div>
 
<script>
const interest = document.getElementById('loan-interest').value;
var input = document.getElementById("loan-amount");
if (interest == 27) {//ORDINARIO
            input.setAttribute("max", 5000000);
            input.setAttribute("min", 600);
        } else if (interest == 18) {//CREDICONFIANZA
            input.setAttribute("max", 150000);
            input.setAttribute("min", 600);
        } else if (interest == 22.80) {//TEMPORADA
            input.setAttribute("max", 40000);
            input.setAttribute("min", 600);
        } else if (interest == 13.80) {//TU AUTO
            input.setAttribute("max", 700000);
            input.setAttribute("min", 25000);
        } else if (interest == 11.40) {//TU CASA
            input.setAttribute("max", 2000000);
            input.setAttribute("min", 100000);
 
        }
 
</script>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro

Como cambiar atributos (max, min )de un input al seleccionar opciones en un select

Publicado por Alejandro (15 intervenciones) el 16/06/2023 23:59:06
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
Solo agrega el listener y convertir el valor del <select> a numérico, para evitar problemas.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$('#loan-interest').change(function(){
    const interest = $(this).val();
    var input = document.getElementById("loan-amount");
    if (interest == 27) {//ORDINARIO
        input.setAttribute("max", 5000000);
        input.setAttribute("min", 600);
    } else if (interest == 18) {//CREDICONFIANZA
        input.setAttribute("max", 150000);
        input.setAttribute("min", 600);
    } else if (interest == 22.80) {//TEMPORADA
        input.setAttribute("max", 40000);
        input.setAttribute("min", 600);
    } else if (interest == 13.80) {//TU AUTO
        input.setAttribute("max", 700000);
        input.setAttribute("min", 25000);
    } else if (interest == 11.40) {//TU CASA
        input.setAttribute("max", 2000000);
        input.setAttribute("min", 100000);
    }
});
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar