Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable a checkbox in javascript and recognize it as checked on the server side

I have a checkbox which in some cases may be disabled and checked using javascript, i.e:

var cbTest = document.getElementById("CheckBoxTest");
cbTest.disabled = true;
cbTest.checked = true;

However, when sending a postback, CheckBoxTest.Checked is false on the server side.

Is it possible to disable the checkbox and still have the server side recognize it as checked?

like image 827
Kuzco Avatar asked Jan 23 '23 10:01

Kuzco


1 Answers

Any disabled control inside a form will not submitted to server on post back. You can add a hidden input control and put the checkbox state to that input and server side check that hidden input value.

like image 59
Emrah GOZCU Avatar answered Jan 24 '23 23:01

Emrah GOZCU