Date field with jQuery does not arrow the chosen value

Asked

Viewed 106 times

0

I am using a datepicker jQuery-UI to generate date in an "input text" field, but I cannot make the date selected in the datepicker set in that input and I do not understand what is wrong.

What is missing in this code so that the input text From and input text Tohave their values changed?

    <script src="/javascripts/jquery/jquery-1.12.4.js"></script>
    <script src="/javascripts/jquery//jquery-ui.js"></script>  <script>
  $( function() {
    var dtFormat = "dd/mm/yy",
      from = $( "#from" )
        .datepicker({
          //defaultDate: "+1w",
          changeMonth: true,
          numberOfMonths: 1,
          dateFormat: dtFormat,
          altFormat: "yy-mm-dd"
        })
        .on( "change", function() {
          to.datepicker( "option", "minDate", getDate( this ) );
        }),
      to = $( "#to" ).datepicker({
        //defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        dateFormat: dtFormat,
        altFormat: "yy-mm-dd"
      })
      .on( "change", function() {
        from.datepicker( "option", "maxDate", getDate( this ) );
      });

    function getDate( element ) {
      var date;
      try {
        date = $.datepicker.parseDate( dtFormat, element.value );
      } catch( error ) {
        date = null;
      }

      return date;
    }
  } );
  </script>
  </head>
  <body>
    <form class="form-horizontal well" method="post" action="/report">
      <label for="from">From</label>
      <input type="text" id="from" name="from">
      <label for="to">To</label>
      <input type="text" id="to" name="to">
      <input class="button btn-default" type="submit" value="Gerar Relatório">
      <table width="100%">

1 answer

0


I got it. In the fields input text from and input text to was missing the attribute value="".

So he stayed :

<input type="text" id="from" name="from" value="">
<input type="text" id="to" name="to" value="">

Thus the values of the dates are sent in the POST.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.