How to call a javascript function from inside jQuery? -


i trying clean code , separate different functions. not working , think has scope. trying execute loadsubscriberlist() inside jquery change event listener.

showuserlist: function (res) {     $('#cvuser').append('<option value="">  - select user - </option ');     $.each(res.userlist, function (key, value) {         $('#cvuser').append('<option value="' + value.id + '">' + value.firstname + " " + value.lastname + " " + value.userid + '</option>');     });      $('#cvuser').on('keyup change', function () {         if ($('#cvuser').val()) {             $('#subscriberselectview').html('');             var showsubscribers = $($("#subscriberselect").text());             $("#subscriberselectview").append(showsubscribers);             this.loadsubscriberlist();         } else {             $('#subscriberselectview').html('');         }     }); },  loadsubscriberlist: function () {     var postdata = {         'usr': $('#cvuser').val()     }      appns.tpmbase.ajaxreq(         '',         postdata,         '/rsc/cvr/gsl',         null,         null,         $.proxy(this.handleshowuserlist, this)     ) }, 

uncaught typeerror: this.loadsubscriberlist not function

can try this,

$('#cvuser').on('keyup change', function () {   if($('#cvuser').val()){     $('#subscriberselectview').html('');     var showsubscribers = $($("#subscriberselect").text());     $("#subscriberselectview").append( showsubscribers );      loadsubscriberlist($('#cvuser').val());   }   else {     $('#subscriberselectview').html('');   } }); } ,  loadsubscriberlist: function(cvuserval) {   var postdata = {    'usr': cvuserval   } 

changed this.loadsubscriberlist() loadsubscriberlist($('#cvuser').val()); , added cvuserval parameter loadsubscriberlist() function.


Comments