Forums

Disable a Field but Save to Database

spytech 06 Jun, 2020
Hi, I have a field: deposit_total and I am using JavaScript to calculate the field. I don't want users to input in the field so I have to disable it so they can see the total.

When I do this it will not save to the Database. What is the best way to save this to the database?

My code:
$("#rent_advance,#room_bond,#dps_deposit").on("change", function(){
$("#deposit_total").val(parseInt($("#rent_advance").val()) + parseInt($("#room_bond").val()) + parseInt($("#dps_deposit").val()));
});
healyhatman 06 Jun, 2020
Calculate it again using PHP after submit.,
spytech 06 Jun, 2020
I found a simple way to do it, I added an event on the Submit button to re-enable it. Works!

healyhatman 06 Jun, 2020
No that's terrible. If you do it that way I can just manually set the value and send it
GreyHead 07 Jun, 2020
Hi spytech,

Disabled fields are not submitted - you need to set it to readonly instead.

And Healyhatman is correct - re-check the calculation after the form is submitted. It's easy enough to edit readonly inputs in the browser if you know what you are doing.

Bob
spytech 07 Jun, 2020
Hi, this works becuase it is staff who are filling this in so they will have no reason to fiddle with the amounts.
Thanks.
This topic is locked and no more replies can be posted.