javascript function to prevent user from changing the value of a specific columnWhich “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?How to change an element's class with JavaScript?How do I remove a property from a JavaScript object?How to insert an item into an array at a specific index (JavaScript)?Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?Get selected value in dropdown list using JavaScript?Generating random whole numbers in JavaScript in a specific range?Is there a standard function to check for null, undefined, or blank variables in JavaScript?How do I remove a particular element from an array in JavaScript?

Check if a string is entirely made of the same substring

Do I have an "anti-research" personality?

What happens to Mjolnir (Thor's hammer) at the end of Endgame?

Don’t seats that recline flat defeat the purpose of having seatbelts?

Converting a sprinkler system's 24V AC outputs to 3.3V DC logic inputs

Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?

Could the terminal length of components like resistors be reduced?

"You've called the wrong number" or "You called the wrong number"

How come there are so many candidates for the 2020 Democratic party presidential nomination?

What does ゆーか mean?

Is it idiomatic to construct against `this`

Critique of timeline aesthetic

Contradiction proof for inequality of P and NP?

How to limit Drive Letters Windows assigns to new removable USB drives

Why must Chinese maps be obfuscated?

Checks user level and limit the data before saving it to mongoDB

How to not starve gigantic beasts

Extension of 2-adic valuation to the real numbers

Why does Mind Blank stop the Feeblemind spell?

Classification of surfaces

Does tea made with boiling water cool faster than tea made with boiled (but still hot) water?

What are the steps to solving this definite integral?

Rivers without rain

How could Tony Stark make this in Endgame?



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


Which “href” value should I use for JavaScript links, “#” or “javascript:void(0)”?How to change an element's class with JavaScript?How do I remove a property from a JavaScript object?How to insert an item into an array at a specific index (JavaScript)?Set a default parameter value for a JavaScript functionHow can I get query string values in JavaScript?Get selected value in dropdown list using JavaScript?Generating random whole numbers in JavaScript in a specific range?Is there a standard function to check for null, undefined, or blank variables in JavaScript?How do I remove a particular element from an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















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










share|improve this question

















  • 2





    Welcome to Stack Overflow. Where is the function EnableCol defined? Could you include the essential part of the HTML also?

    – trincot
    Mar 9 at 8:05











  • I'm not sure how to solve your problem, but I thought someone should note that this code suggests end users will be able to run arbitrary SQL, meaning they can do whatever they want with your database. If this is for a public website, there should probably be a safer API between the frontend and the database.

    – Nicholas
    Mar 9 at 8:08











  • Thanks . I have a data entry form on my application and a sql - server table which is the base and this is the Java script above on that form .if the user see the value on the 'datekey' column / field , he should not be able to change the value . I need that ! thanks

    – Pantea Tourang
    Mar 9 at 8:11











  • Dear @Nicholas . The field is a date field and user can not type anything . He should choose from the dates that are shown to him . so it's ok

    – Pantea Tourang
    Mar 9 at 8:16






  • 1





    @Pantea Tourang, if you trust your users then you are right, but a user could always open the console and type RunSql("drop table ProjectExecution.Contractinfo"). I'm not sure what context this will be used in, so maybe your users will be trustworthy, but I thought mention it just in case.

    – Nicholas
    Mar 9 at 8:30

















0















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










share|improve this question

















  • 2





    Welcome to Stack Overflow. Where is the function EnableCol defined? Could you include the essential part of the HTML also?

    – trincot
    Mar 9 at 8:05











  • I'm not sure how to solve your problem, but I thought someone should note that this code suggests end users will be able to run arbitrary SQL, meaning they can do whatever they want with your database. If this is for a public website, there should probably be a safer API between the frontend and the database.

    – Nicholas
    Mar 9 at 8:08











  • Thanks . I have a data entry form on my application and a sql - server table which is the base and this is the Java script above on that form .if the user see the value on the 'datekey' column / field , he should not be able to change the value . I need that ! thanks

    – Pantea Tourang
    Mar 9 at 8:11











  • Dear @Nicholas . The field is a date field and user can not type anything . He should choose from the dates that are shown to him . so it's ok

    – Pantea Tourang
    Mar 9 at 8:16






  • 1





    @Pantea Tourang, if you trust your users then you are right, but a user could always open the console and type RunSql("drop table ProjectExecution.Contractinfo"). I'm not sure what context this will be used in, so maybe your users will be trustworthy, but I thought mention it just in case.

    – Nicholas
    Mar 9 at 8:30













0












0








0








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










share|improve this question














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







javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 9 at 8:00









Pantea TourangPantea Tourang

32




32







  • 2





    Welcome to Stack Overflow. Where is the function EnableCol defined? Could you include the essential part of the HTML also?

    – trincot
    Mar 9 at 8:05











  • I'm not sure how to solve your problem, but I thought someone should note that this code suggests end users will be able to run arbitrary SQL, meaning they can do whatever they want with your database. If this is for a public website, there should probably be a safer API between the frontend and the database.

    – Nicholas
    Mar 9 at 8:08











  • Thanks . I have a data entry form on my application and a sql - server table which is the base and this is the Java script above on that form .if the user see the value on the 'datekey' column / field , he should not be able to change the value . I need that ! thanks

    – Pantea Tourang
    Mar 9 at 8:11











  • Dear @Nicholas . The field is a date field and user can not type anything . He should choose from the dates that are shown to him . so it's ok

    – Pantea Tourang
    Mar 9 at 8:16






  • 1





    @Pantea Tourang, if you trust your users then you are right, but a user could always open the console and type RunSql("drop table ProjectExecution.Contractinfo"). I'm not sure what context this will be used in, so maybe your users will be trustworthy, but I thought mention it just in case.

    – Nicholas
    Mar 9 at 8:30












  • 2





    Welcome to Stack Overflow. Where is the function EnableCol defined? Could you include the essential part of the HTML also?

    – trincot
    Mar 9 at 8:05











  • I'm not sure how to solve your problem, but I thought someone should note that this code suggests end users will be able to run arbitrary SQL, meaning they can do whatever they want with your database. If this is for a public website, there should probably be a safer API between the frontend and the database.

    – Nicholas
    Mar 9 at 8:08











  • Thanks . I have a data entry form on my application and a sql - server table which is the base and this is the Java script above on that form .if the user see the value on the 'datekey' column / field , he should not be able to change the value . I need that ! thanks

    – Pantea Tourang
    Mar 9 at 8:11











  • Dear @Nicholas . The field is a date field and user can not type anything . He should choose from the dates that are shown to him . so it's ok

    – Pantea Tourang
    Mar 9 at 8:16






  • 1





    @Pantea Tourang, if you trust your users then you are right, but a user could always open the console and type RunSql("drop table ProjectExecution.Contractinfo"). I'm not sure what context this will be used in, so maybe your users will be trustworthy, but I thought mention it just in case.

    – Nicholas
    Mar 9 at 8:30







2




2





Welcome to Stack Overflow. Where is the function EnableCol defined? Could you include the essential part of the HTML also?

– trincot
Mar 9 at 8:05





Welcome to Stack Overflow. Where is the function EnableCol defined? Could you include the essential part of the HTML also?

– trincot
Mar 9 at 8:05













I'm not sure how to solve your problem, but I thought someone should note that this code suggests end users will be able to run arbitrary SQL, meaning they can do whatever they want with your database. If this is for a public website, there should probably be a safer API between the frontend and the database.

– Nicholas
Mar 9 at 8:08





I'm not sure how to solve your problem, but I thought someone should note that this code suggests end users will be able to run arbitrary SQL, meaning they can do whatever they want with your database. If this is for a public website, there should probably be a safer API between the frontend and the database.

– Nicholas
Mar 9 at 8:08













Thanks . I have a data entry form on my application and a sql - server table which is the base and this is the Java script above on that form .if the user see the value on the 'datekey' column / field , he should not be able to change the value . I need that ! thanks

– Pantea Tourang
Mar 9 at 8:11





Thanks . I have a data entry form on my application and a sql - server table which is the base and this is the Java script above on that form .if the user see the value on the 'datekey' column / field , he should not be able to change the value . I need that ! thanks

– Pantea Tourang
Mar 9 at 8:11













Dear @Nicholas . The field is a date field and user can not type anything . He should choose from the dates that are shown to him . so it's ok

– Pantea Tourang
Mar 9 at 8:16





Dear @Nicholas . The field is a date field and user can not type anything . He should choose from the dates that are shown to him . so it's ok

– Pantea Tourang
Mar 9 at 8:16




1




1





@Pantea Tourang, if you trust your users then you are right, but a user could always open the console and type RunSql("drop table ProjectExecution.Contractinfo"). I'm not sure what context this will be used in, so maybe your users will be trustworthy, but I thought mention it just in case.

– Nicholas
Mar 9 at 8:30





@Pantea Tourang, if you trust your users then you are right, but a user could always open the console and type RunSql("drop table ProjectExecution.Contractinfo"). I'm not sure what context this will be used in, so maybe your users will be trustworthy, but I thought mention it just in case.

– Nicholas
Mar 9 at 8:30












1 Answer
1






active

oldest

votes


















0














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");






share|improve this answer























  • Thanks but the problem is the record won't be inserted cause it passes null for the column you have disabled !!! and the column is not Nullable !!

    – Pantea Tourang
    Mar 9 at 9:26











  • No, it won't pass null record even though it is disabled. You can fetch its value by $("#input_DateKey").val()

    – ravi
    Mar 9 at 9:43











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55075238%2fjavascript-function-to-prevent-user-from-changing-the-value-of-a-specific-column%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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");






share|improve this answer























  • Thanks but the problem is the record won't be inserted cause it passes null for the column you have disabled !!! and the column is not Nullable !!

    – Pantea Tourang
    Mar 9 at 9:26











  • No, it won't pass null record even though it is disabled. You can fetch its value by $("#input_DateKey").val()

    – ravi
    Mar 9 at 9:43















0














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");






share|improve this answer























  • Thanks but the problem is the record won't be inserted cause it passes null for the column you have disabled !!! and the column is not Nullable !!

    – Pantea Tourang
    Mar 9 at 9:26











  • No, it won't pass null record even though it is disabled. You can fetch its value by $("#input_DateKey").val()

    – ravi
    Mar 9 at 9:43













0












0








0







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");






share|improve this answer













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");







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 9 at 9:17









raviravi

521619




521619












  • Thanks but the problem is the record won't be inserted cause it passes null for the column you have disabled !!! and the column is not Nullable !!

    – Pantea Tourang
    Mar 9 at 9:26











  • No, it won't pass null record even though it is disabled. You can fetch its value by $("#input_DateKey").val()

    – ravi
    Mar 9 at 9:43

















  • Thanks but the problem is the record won't be inserted cause it passes null for the column you have disabled !!! and the column is not Nullable !!

    – Pantea Tourang
    Mar 9 at 9:26











  • No, it won't pass null record even though it is disabled. You can fetch its value by $("#input_DateKey").val()

    – ravi
    Mar 9 at 9:43
















Thanks but the problem is the record won't be inserted cause it passes null for the column you have disabled !!! and the column is not Nullable !!

– Pantea Tourang
Mar 9 at 9:26





Thanks but the problem is the record won't be inserted cause it passes null for the column you have disabled !!! and the column is not Nullable !!

– Pantea Tourang
Mar 9 at 9:26













No, it won't pass null record even though it is disabled. You can fetch its value by $("#input_DateKey").val()

– ravi
Mar 9 at 9:43





No, it won't pass null record even though it is disabled. You can fetch its value by $("#input_DateKey").val()

– ravi
Mar 9 at 9:43



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55075238%2fjavascript-function-to-prevent-user-from-changing-the-value-of-a-specific-column%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved