0
votes

I have a working code for a date-picker like this :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <style>
      .footer {position: fixed;left: 0;bottom: 0;width: 100%;background-color: red;color: white;text-align: center;}
    </style>
  </head>
  <body>
    <div class="footer">
      <form>
        <input type="text" id="datepicker" name="tgl" />
        <input type="submit" name="submit" />
      </form>
    </div>
    <script>
      $(function() {
        $("#datepicker").datepicker();
      });
      $("#datepicker").datepicker({
        dateFormat: "dd M yy"
      }).datepicker("setDate", new Date());
    </script>
  </body>
</html>

Jsfiddle Link

Above is a short version code.
Basically, after the user select the date then click submit button, it will query to insert the submitted data to a SQL database. No problem here.

But because the page mostly is opened in a cellphone, if the user tap the input type text-box, the keyboard from the cellphone show up, blocking the date-picker. I don't want this.

So I change the input type "text" into type "button", (the cellphone keyboard not show up anymore when I tap the button) and I see each time I tap another date in the date picker, the button label/value show the date accordingly.

Then I reluctantly tap the submit button, but in the SQL table result - it shows a wrong date and it alway give the result as 1970-01-01 no matter what date I pick in the date picker. So I think it maybe because the "tgl" has no value if I change it to a button type - and the "tgl" has the selected date-picker value after I change it back to a text type and the date SQL table show a correct date.

I have searched the internet in case there is someone with a similar problem with me, but I can't find one. So my question is : how to have the input type button value where the value comes from the selected date in the date-picker ?

1
@RobMoll, wow that's fast reply and it works magically. Thank you so much. Sorry I miss the that same topic like mine here in S.O. Thanks once again.karma

1 Answers

1
votes

use the attribute readonly to the input field and make the input field type as date.