Avoid changing value of the Textbox field

Peter_1985 2,866 Reputation points
2022-01-02T15:33:27.56+00:00

Hi,
I added the following codes to the relevant Textbox field, and it did assign today value to that field. How to avoid changing value of the relevant Textbox field?

    $(function () {
        $("#tb_valid_from").datepicker({
            autoclose: true,
            todayHighlight: false
        }).datepicker('update', new Date());
    });
Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | ASP.NET | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-01-03T02:35:03.157+00:00

    Hi @Peter_1985 ,

    and it did assign today value to that field. How to avoid changing value of the relevant Textbox field?

    According to your code, you are using Bootstrap Datepicker, right?

    To assign today value and make the textbox read-only, you could set the date range and add the readonly property for the textbox.

    Refer to the following sample: Set the datepicker's startDate and endDate property, limit the datepicker to select today.

    <input type="input" class="form-control" id="inputDate" readonly="readonly">   
    $('#inputDate').datepicker({  
                  autoclose: true,  
                  todayHighlight: false,  
                  startDate: new Date(),   
                  endDate:new Date(),   
    }).datepicker("setDate",'now');  
    

    The result is like this (you can also view the result from this link):

    161765-image.png


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.