Untitled

 avatar
unknown
plain_text
4 years ago
3.4 kB
5
Indexable
<html>
    <head>
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    </head>
    <body class="container border border-dark p-4 mx-auto">

        <form>
	    
	    <div class="form-group">

			<label for="tipo_moneda">Seleccionar tipo de moneda</label>
			<select class="form-control" id="tipo_moneda" name="tipo_moneda" aria-label="Seleccionar moneda" required>
			  <option>Elegir tipo de moneda...</option>
			  <option value="1">Vender en pesos</option>
			  <option value="2">Vender en dólares</option>
			</select>

	    </div>

	    <div class="form-group" id="div_input_pesos">
	    
			<label for="input_pesos">Ingresar precio en pesos argentinos</label>
			<input type="text" class="form-control" name="precio_pesos" id="input_pesos" placeholder="Precio en pesos (sólo numeros)"/>
		    
         </div>

	    <div class="form-group" id="div_input_dolares">
	    
			<label for="input_dolares">Ingresar precio en dólares estadounidenses</label>
			<input type="text" class="form-control" name="precio_dolares" id="input_dolares" placeholder="Precio en dólares estadounidenses (sólo numeros)"/>
	    
        </div>

	    <button type="submit" class="btn btn-primary">Listo, terminar.</button>

	</form>

	<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
	<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>

    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>

	<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>

        <script>

            $(document).ready(function(){
                console.log('holaa');
            });

		    let select_tipo_moneda = $('#tipo_moneda');

		    select_tipo_moneda.change(function(){
		        
		    	let valor = select_tipo_moneda.val();

				mostrarInputPrecio(valor);

		    });

		    // Divs inputs
		    let div_input_pesos = $('#div_input_pesos');
		    let div_input_dolares = $('#div_input_dolares');

		    // Inputs
		    let input_pesos = $('#input_pesos');
		    let input_dolares = $('#input_dolares');

		    div_input_pesos.hide();

		    div_input_dolares.hide();

		    function mostrarInputPrecio(valor){

		    	if(valor=="1"){

		    		input_dolares.prop('required', false);
		    		input_pesos.prop('required', false);

		    		input_pesos.prop('required', true);
		    		div_input_dolares.hide();
		    		div_input_pesos.show()
		    		input_pesos.focus();

		    	}else{

		    		input_dolares.prop('required', false);
		    		input_pesos.prop('required', false);

		    		input_dolares.prop('required', true);
		    		div_input_pesos.hide();
		    		div_input_dolares.show().focus();
		    		input_dolares.focus();

		    	}

		    }


        </script>

    </body>
</html>
Editor is loading...