简体   繁体   中英

javascript function to prevent user from changing the value of a specific column

Hope you're doing well I'm new to JavaScript and I need your help to complete the code below. I've written a JS code as you can see below :

$("#input_KindCode").change(function () {
if ($(this).val() == 1) {
    RunSql("Select DateKey From ProjectExecution.Contractinfo WHERE PlanCode = " + $("#input_PlanCode").val() + " AND ProjectCode = '" + $("#input_ProjectCode").val() + "' AND  ContractCode = '" + $("#input_ContractCode").val() + "' AND KindCode = 1 ", function (data) {
        if (data.length > 0) {
            $("#input_DateKey").val(data[0].DateKey);
            /////// THIS PART///////
        } else {
            $("#input_DateKey").val('');
            EnableCol("DateKey");
        }
    });
}
else {
    $("#input_DateKey")[0].value = '';
    EnableCol("DateKey");
};});

In the 'RunSql' part of the code , I'm checking whether the 'datekey' column has value if true the value will show up in the field otherwise the user must enter the value for the column.

The problem is I want to add something to the code . I want to show the value if it exists AND I want to disable the column so that the user can not change the value . I can not use the function 'disable column' cause it does not work in my case are there any other functions ??

so I want a function to prevent user from changing the value of the column if it is being shown on the field. the function must be written in the 'This part' part of the code Thanks in advance

You can disable this input field using jquery. To perform this you need to add one line.

Code:

if (data.length > 0) {
            $("#input_DateKey").val(data[0].DateKey);
            $("#input_DateKey").prop('disabled',true);
        } else {
            $("#input_DateKey").val('');
            $("#input_DateKey").prop('disabled',false);
            EnableCol("DateKey");
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM