jquery - How to access & populate dropdown when dropdown wildcard id is stored in varibale -


in case have common routine populate dropdown , when calling routine passing dropdown wild card id routine way

calling way

populatedropwdown(0, 15, '$("select[id*=cboearlycolhrs]")', '09');      function populatedropwdown(startidx, lastidx, targetid, selectedval) {         var listitems = '';         $(targetid).html("");         (var = startidx; <= lastidx; i++) {             if (i == 0) {                 if (i == selectedval)                     listitems += "<option value='" + selectedval + "'>00</option>";                 else                     listitems += "<option value='00'>00</option>";             }             else {                 var valuehrs = '', txtdata = '';                 valuehrs = convertdateto12hrs(i, true);                 txtdata = convertdateto12hrs(i, false);                  if (txtdata == selectedval)                     listitems += "<option value='" + valuehrs + "' option:selected>'" + txtdata + "'</option>";                 else                     listitems += "<option value='" + valuehrs + "'>'" + txtdata + "'</option>";             }         }         $(targetid).html(listitems);     } 

my main problem line not working $(targetid).html(listitems); line $(targetid).html(listitems); suppose re-fill dropdown line not working.

please guide me when wildcard id stored in variable how use variable re-fill dropdown......any idea appreciated. thanks

you're passing in jquery call select element, string won't work that. lot tidier pass in just wildcard part of id , find in function, this...

populatedropwdown(0, 15, 'cboearlycolhrs', '09');  function populatedropwdown(startidx, lastidx, targetid, selectedval) {     var listitems = '';     var $target = $("select[id*=" + targetid + "]");     $target.html("");     (var = startidx; <= lastidx; i++) {         if (i == 0) {             if (i == selectedval)                 listitems += "<option value='" + selectedval + "'>00</option>";             else                 listitems += "<option value='00'>00</option>";         }         else {             var valuehrs = '', txtdata = '';             valuehrs = convertdateto12hrs(i, true);             txtdata = convertdateto12hrs(i, false);              if (txtdata == selectedval)                 listitems += "<option value='" + valuehrs + "' option:selected>'" + txtdata + "'</option>";             else                 listitems += "<option value='" + valuehrs + "'>'" + txtdata + "'</option>";         }     }     $target.html(listitems); } 

i created $target variable don't have search same element twice.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -