Disable text input change but take it with its value in jQuery

4.8k views Asked by At

I am filling textbox elements with some data come from database. I am using the same form for different roles. Some roles can update these values but others cannot. So, I want to disable them for edit.

I both used:

$("input:eq(1)").attr("disabled", true); 

and

$("input:eq(2)").prop('disabled', true);

It works seemingly but when I try to update the form, these values are stored null in database. At first it fetches and fills the textboxes disabled, but when I click update button, the values are sent to DB as null. How can I avoid that problem and provide a solution to push unchanged (because you cannot change) input values into DB?

1

There are 1 answers

0
Tim Lewis On BEST ANSWER

The issue with disabled inputs is that they don't get passed to the database on a submit post. Try changing them to this:

$("input:eq(1)").attr("readonly", true);