locked
Jquery DataPicker RRS feed

  • Question

  • User-797751191 posted

    Hi

       In Jquery DatePicker is it possible that user should only able to select Data , should not be able to enter manually.

    I am trying below code , User is not able to enter but user is able to delete content which also i want to be disabled.

    $("#my_txtbox").keypress(function(event) {event.preventDefault();});

    <script>
    $(function () {
    $(".datepicker").datepicker(
    {
    dateFormat: 'dd-mm-yy',
    maxDate: new Date
    });
    $("#my_txtbox").keypress(function (event) { event.preventDefault(); });
    });
    </script>

    Thanks

    Tuesday, July 16, 2019 2:19 AM

Answers

  • User288213138 posted

    Hi jsshivalik,

    I am very sorry, it should be setting the property in the TextBox ReadOnly="true"

    <asp:TextBox ID="txtDate" runat="server" ReadOnly="true"></asp:TextBox>

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 16, 2019 6:52 AM

All replies

  • User288213138 posted

    Hi jsshivalik,

    If you want the user to neither enter nor delete,you can set the ReadOnly property in Textbox to true.

    The code:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
        <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="Stylesheet" type="text/css" />
    
    
        <script type="text/javascript">
            $(function () {
                $("[id*=txtDate]").datepicker({                             
                });
            });
        </script>
    
           <div>
                <asp:TextBox ID="txtDate" runat="server" ReadOnly="true"></asp:TextBox>
            </div>
    

    The result:

    Best regards,

    Sam

    Tuesday, July 16, 2019 5:53 AM
  • User-797751191 posted

    Hi Samwu

      After selecting i am still able to delete

    Thanks

    Tuesday, July 16, 2019 6:36 AM
  • User288213138 posted

    Hi jsshivalik,

    I am very sorry, it should be setting the property in the TextBox ReadOnly="true"

    <asp:TextBox ID="txtDate" runat="server" ReadOnly="true"></asp:TextBox>

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 16, 2019 6:52 AM
  • User-797751191 posted

    Hi Samwu

      When i use readonly it does not pass value in a session

    Thanks

    Tuesday, July 16, 2019 9:27 AM
  • User475983607 posted

    When i use readonly it does not pass value in a session

    Web Forms does not change the text input when set to ReadOnly as described in the docs.  Session is a different feature entirely. 

    https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.textbox.readonly?view=netframework-4.8

    You've posted several similar threads and I thought this issue was solved by using standard ASP.NET validation controls to force a specific input format.

    Tuesday, July 16, 2019 3:27 PM