2

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?

JoshuaJeanThree
  • 1,382
  • 2
  • 22
  • 41
  • `disabled` inputs still have values, how are you re-grabbing the values to send back to the DB... `("input:eq(2)").val()` still returns a value even if it's disabled. – tymeJV Dec 24 '14 at 17:11
  • actually I am working on a written project and I could not the function which stores data to DB. It creates custom forms dynamically in PHP and there are thousands of code I am looking for the method but I could not find. Input elements are generated dynamically and have no id or class as I see. I interfere to only html-jquery layer. Sorry for my deficiency. – JoshuaJeanThree Dec 24 '14 at 17:21
  • But readonly attribute worked... – JoshuaJeanThree Dec 24 '14 at 17:23
  • @JoshuaJeanThree disabled cannot pass value to DB.You may take these values by hidden input field(s). – Raham Dec 24 '14 at 17:25

1 Answers1

4

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); 
Tim Lewis
  • 27,813
  • 13
  • 73
  • 102