get input value for minDate

0

With the function below, it goes through dates from and to, through a calendar.
I need to click on the 'until' input to get the 'from' input date to inform the minDate.
How I'm doing it:
minDate: $ ("# from" + x) .val ().
.. it does not work for me.
Thank you very much

var x = 1;

            $(addButton).click(function(){ //Once add button is clicked
                if(x < maxField){ //Check maximum number of input fields
                    x++; z++;
                    //Increment field counter
                    var fieldContainer = $(fieldContainerHTML);

var fieldContainerHTML = '<div ><a href="javascript:void(0);" class="remove" ><img src="calendario/images/delete.png"  /><br /></a><div><br/>';

var fieldInput  = $('<input type="text" name="desde['+x+']" id="desde'+x+'" class="uno" size="9" placeholder="Desde"/> &nbsp;').calendario({time: false,    clearButton: true,  }); 
var fieldInput2  = $('<input type="text" name="hasta['+x+']" id="hasta'+x+'" size="9" class="dos" placeholder="Hasta"/>').calendario({time: false,  clearButton: true, minDate: $("#desde"+x).val() }); 
var fieldInputHTML  = ' &nbsp;<select name="alias['+x+']" id="alias'+x+'"  class="requerido" style="width: 90px;">  <option value="" selected="selected">Apartamento</option><?php echo $casas; ?>  &nbsp;  <input type="text" class="importe" name="precio['+x+']" id="precio'+x+'" size="7" placeholder="Precio día"/>  <input type="hidden"  name="seleccion['+x+']"  value="tarifa" />';   

var fieldContainer = $(fieldContainerHTML); //Construimos el objeto jquery y lo guardamos en una variable para hacer referencia después.
fieldContainer.prepend(fieldInput,fieldInput2,fieldInputHTML); // Añadimos el input al html contenedor
$(wrapper).append(fieldContainer); // Añadimos los nodos html al wrapper            
// Construimos el input y le asociamos el datepicker
                }
            });
    
asked by Angel Llorente 17.01.2018 в 01:22
source

1 answer

0

The code of the question has a lot of "noise". Here is an example using pure JavaScript:

The following adds the date of the "From" field as the minimum date of the "Until" field when leaving the first field.

var desde = document.getElementById('desde');
desde.addEventListener('change', setMin);

function setMin() {
  var hasta = document.getElementById('hasta');
  hasta.min = desde.value;
}
<div>Desde: <input type="date" id="desde"></div>
<div>Hasta: <input type="date" id="hasta"></div>
    
answered by 04.02.2018 в 04:34