javascript - How to get ClientID in a variable -


i have 7 check boxes 7 weeks , separate time picker 7 days on page. when check box checked want show time picker week day, , if unchecked want hide respective time picker

i have used following code this, , working too.

function chk_weekday_clicked(ctrl, week) {     if (ctrl.checked) {         if (week == "monday")             document.getelementbyid("<%= tm_monday_from.clientid %>").style.display = "";         else if (week == "tuesday")             document.getelementbyid("<%= tm_tuesday_from.clientid %>").style.display = "";         else if (week == "wednesday")             document.getelementbyid("<%= tm_wednesday_from.clientid %>").style.display = "";        //rest of days      }     else{         if (week == "monday")             document.getelementbyid("<%= tm_monday_from.clientid %>").style.display = "none";         else if (week == "tuesday")             document.getelementbyid("<%= tm_tuesday_from.clientid %>").style.display = "none";         else if (week == "wednesday")             document.getelementbyid("<%= tm_wednesday_from.clientid %>").style.display = "none";         //rest of days      } } 

chk_weekday_clicked event handler week day check box. first parameter clicked checkbox control , second parameter name of week day.

all time picker control's name have same naming patterned as, tm_[weekname]_from

so, question instead of using these many if-else can in couple of lines? code below.

function chk_weekday_clicked(ctrl, week) {     //i want controlid using parameter. , must clientid using on page having masterpage.     var controlid = "tm_" + week + "_from";     if (ctrl.checked) {         document.getelementbyid(controlid).style.display = "";     }     else {         document.getelementbyid(controlid).style.display = "none";         } } 

my actual problem how can control's clientid in variable. page using master page, must use clientid controls id.

so, can suggest solution this

clientid generated asp.net, can't created using javascript variable. can this

function chk_weekday_clicked(ctrl, week) {      //since client id generated asp.net     //create list of ids     var controls  = {         "monday" : "<%= tm_monday_from.clientid %>",         "tuesday" : "<%= tm_tuesday_from.clientid %>",         "wednesday" : "<%= tm_wednesday_from.clientid %>",     }      //fetch control id     var controlid = controls[week.tolowercase()];      //desired operation     if (ctrl.checked) {         document.getelementbyid(controlid).style.display = "";     }     else{         document.getelementbyid(controlid).style.display = "none";     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -