129

I decided to use the JQuery UI Datepicker script for picking dates. Below is part of my code, and the way I integrated it into my PHP page:

<link type="text/css" href="css/south-street/jquery-ui-1.8.6.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.6.custom.min.js"></script>
<script type="text/javascript">
$(function(){
    // Datepicker
    $('#datepicker').datepicker({ dateFormat: 'yy-mm-dd' });
    //hover states on the static widgets
    $('#dialog_link, ul#icons li').hover(
        function() { $(this).addClass('ui-state-hover'); }, 
        function() { $(this).removeClass('ui-state-hover'); }
    );
});
</script>

And:

    // date picker (embeds JQuery script)
echo '<label for="datepicker">Date: </label>';
echo '<input type="text" name="datepicker" id="datepicker" />';
echo '<div id="datepicker"></div>';

Pretty much according to the JQuery UI instructions.

Now my question is: how can I disable manual inputs in the text input field? I only want the JQuery Datepicker script to be able to fill the text field. As far as I can see, the script currently prevents the user from entering any non-numerical characters into the text field, but any combination of numbers is allowed (therefore, gibberish like "95460829468" is allowed).

Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
BeeDog
  • 1,835
  • 5
  • 17
  • 20

2 Answers2

317

When you make the input, set it to be readonly.

<input type="text" name="datepicker" id="datepicker" readonly="readonly" />
Matthew Jacobs
  • 4,344
  • 1
  • 20
  • 20
35

I think you should add style="background:white;" to make looks like it is writable

<input type="text" size="23" name="dateMonthly" id="dateMonthly" readonly="readonly"   style="background:white;"/>
Karim Samir
  • 1,470
  • 17
  • 17
  • 7
    1. copy answer 2. add new attribute (I think you should add style="background:white;" to make looks like it is writable and "cursor: pointer" to make it look clickable) 3. ??????? 4. Profit – skmasq Jul 04 '16 at 16:33
  • To be fair, the CSS tip was actually pretty helpful so that the input doesn't appear disabled. – Hartley Brody Jul 31 '19 at 23:18