Avoid changing value of the Textbox field

Peter_1985 2,526 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());
    });
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,204 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,288 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,021 Reputation points Microsoft Vendor
    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