asp.net - JQuery enable/disable asp:Textboxes based on selected asp:CheckBoxList -


i working on project users need enter working hours if day of week selected. users have requested fields disabled until day checked.

ideally keep smart , dynamic possible, using day value build input, rather writing separate conditions based on each day.

here's basic setup far:

https://i.imgur.com/vhbvzs3.png

and jquery catch click event, , build object name:

   $("input[type=checkbox][id*=cbldays]").click(function () {                 if (this.checked) {                     var day = $(this).val();                     var startcontrolid = "txtnewstart" + day;                     var finishcontrolid = "txtnewfinish" + day;                     var lunchcontrolid = "ddllunchnew" + day;                     $this.find('input[name$=' + startcontrolid + ']').attr("disabled", false);                  } 

i have proven "startcontrolid" variable being populated correct id, issue having is selector doesnt appear finding control.

does 1 have idea i'm going wrong?

i managed find solution out in future - changed clientidmode property "static" on asp:textboxes , modified jquery selector to:
$("[id$=" + startcontrolid + "]").attr("disabled", false);

so entire jquery function is:

$("input[type=checkbox][id*=cbldays]").click(function () {

            if (this.checked) {                 var day = $(this).val();                 var startcontrolid = "txtnewstart" + day;                 var finishcontrolid = "txtnewfinish" + day;                 var lunchcontrolid = "ddllunchnew" + day;                 $("[id$=" + startcontrolid + "]").attr("disabled", false);                 $("[id$=" + finishcontrolid + "]").attr("disabled", false);                 $("[id$=" + lunchcontrolid + "]").attr("disabled", false);             }             else {                 var day = $(this).val();                 var startcontrolid = "txtnewstart" + day;                 var finishcontrolid = "txtnewfinish" + day;                 var lunchcontrolid = "ddllunchnew" + day;                 $("[id$=" + startcontrolid + "]").attr("disabled", true);                 $("[id$=" + finishcontrolid + "]").attr("disabled", true);                 $("[id$=" + lunchcontrolid + "]").attr("disabled", true);             }         }); 

hope saves in future land time!


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -