Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
Need to add range limit of 30 days on 'To date' once user selects 'From date' in JavaScript

Need to add range limit of 30 days on To date once user selects From date in javascript.

I have tried using it the way its been shown below, but it isn't working.

Tried using max date too but it doesn't work dynamically depending on user selection.

Need to use datepicker only.

$(document).ready(function() {
    
    $('#csFromdt').datepicker({
        dateFormat : 'dd/mm/yy',
        changeMonth : true,
        changeYear : true,
        onSelect : function(selected) {
            $("#csTodt").datepicker("option", "minDate", selected)
        }
    });

    $("#csFromdt").keyup(function(e) {

        if (e.keyCode != 8) {
            if ($(this).val().length == 2) {
                $(this).val($(this).val() + "/");
            } else if ($(this).val().length == 5) {
                $(this).val($(this).val() + "/");
            }
        }
    });

    $('#csTodt').datepicker({
        dateFormat : 'dd/mm/yy',
        changeMonth : true,
        changeYear : true
        /*maxDays: 10*/
        /*maxDate : '15'*/
    })/*.on('changeDate', function(selected) {
        let csFromdt = new Date(selected.date.valueOf());
        let csTodt = new Date(csFromdt);
        csTodt = new Date(csTodt.setDate(csTodt.getDate() + 15));
        $('#csTodt').datepicker('setStartDate', csFromdt);
        $('#csTodt').datepicker('setEndDate', csTodt);
      });*/


    $("#csTodt").keyup(function(e) {
        if (e.keyCode != 8) {
            if ($(this).val().length == 2) {
                $(this).val($(this).val() + "/");
            } else if ($(this).val().length == 5) {
                $(this).val($(this).val() + "/");
            }
        }
    });

    $(".datepicker").datepicker({
        dateFormat : 'dd/mm/yy',
        changeMonth : true,
        changeYear : true,
        maxDate : '0'
    });

});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I tried my best..any query ask me

  <script type="text/javascript">
     $(document).ready(function(){
      
       // initializing jquery datepicker
       $( "#csFromdt, #csTodt" ).datepicker({
         dateFormat : 'dd/mm/yy',
         changeMonth : true,
         changeYear : true,
       });
     
       $("#csFromdt").change(function(){ 
         var fromdate = $("#csFromdt").val();
     
         // from dd/mm/yy to new date(yyyy, mm, dd) format
         var newdate = fromdate.split("/");
         var nd = new Date(+newdate[2], newdate[1] - 1, +newdate[0]); //newdate[0] = dd; newdate[1] = mm, newdate[2] = yy
         nd.setDate(nd.getDate() + 30); //adding 30 days from  fromdate
         $("#csTodt").removeAttr('disabled'); //disabling the csTodt input box //optional if u disabled todate input box
     
         $('#csTodt').datepicker('option', 'minDate', fromdate); //setting min  date
         $('#csTodt').datepicker('option', 'maxDate', nd); //setting  max date
     
       });
     
     });
  </script>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda