javascript - Use keyup function in custom jQuery class -


i have custom jquery class create popup list, when pass html elements class objects undefined!

i want send element class , set .keyup() event , manipulate element value in .keyup() function.

my code is:

$.class('kpopup', {     // static     init: function (e, p, h, r, u) {         url = u;         hostelement = e;         popupelement = p;         popupresult = r;         hiddenelement = h;          $(hostelement).keyup(function () {             $.ajax({                 url: url,                 data: { "value": $(hostelement).val() },                 type: 'post',                 success: function (dt) {                     if (dt != "") {                         $(popupresult).html(dt);                         $(hostelement).popupdiv($(popupelement));                     } else {                         $(popupelement).hide();                     }                 }             });         });     } }, //prototypes {}); 

code using above class:

$(document).ready(function () {     var kpopup = new kpopup(         $("#clas_academy_id"),         $(".popup-picker"),         $("#clas_academy_id_hidden"),         $("#popup-result"),         '@url.action("searchacademies","academy")'     ); }); 

maybe can try this, press f12 in chrome or control+shift+k in firefox open console , inspect output. can click on of console.log outputs inspect values of objects logged.

kpopup = function(e, p, h, r, u) {   console.log("creating kpopup parameters:", e, p, h, r, u);   this.url = u;   this.hostelement = e;   this.popupelement = p;   tis.popupresult = r;   this.hiddenelement = h;   this.init(); }; kpopup.prototype.init = function() {   console.log("and is:", this);   console.log("and hostelement is:", this.hostelement);   var presult = this.popupresult;   var helement = this.hostelement;   var pelement = this.popupelement;   this.hostelement.keyup(function() {     $.ajax({       url: this.url,       data: {"value": helement.val()},       type: 'post',       success: function(dt) {         if (dt !== "") {           presult.html(dt);           helement.popupdiv(pelement);         } else {           pelement.hide();         }       }     });   }); }; 

note capitalised kpopup object because that's usual notation constructor functions document ready have capitalise well:

$(document).ready(function () {     var kpopup = new kpopup(         $("#clas_academy_id"),         $(".popup-picker"),         $("#clas_academy_id_hidden"),         $("#popup-result"),         '@url.action("searchacademies","academy")'     ); }); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -