Thanks! That worked like a charm and will help me in the future. I appreciate your help very much and I love your listen plugin!
On Apr 8, 6:25 pm, Ariel Flesler <[EMAIL PROTECTED]> wrote: > The problem is that your 'this' changed. > > See: > $j.getJSON( ..., function(){ > //the this in here, is not the same as in the code before the > getJSON. > }); > > You need to do: > var self = this; > > before calling getJSON, and then, inside this function, use self > instead of this. > You can name 'self' the way you like. > > Cheers > > -- > Ariel Fleslerhttp://flesler.blogspot.com > > On 8 abr, 17:34, hl <[EMAIL PROTECTED]> wrote: > > > Hello. I'm somewhat new to javascript, primarily used to PHP, and I > > have been attempting to revamp my javascript code base using jQuery > > and some class structure. > > > However, I'm getting the error "this.checkRequired is not a function". > > > From what I can find the documentation on classes in javascript online > > is very sparse and there seem to be multiple ways of doing it, it is > > somewhat confusing. I am not sure if I am even properly declaring > > things. > > > I am wondering if anyone can point out a basic mistake that I am > > making or something, it's driving me crazy and is roadblocking my > > progress. > > > I call the class as follows: > > _________________________ > > //element validation > > jQuery.listen( "blur", ".validated", function(){ > > //if the field has a value > > if( $j( this ).fieldValue() != "" ) { > > //validate it > > var validator = new Validator(); > > validator.validateElement( this ) > > } > > }); > > _____________________ > > > The code for the class is below: > > ________________________________ > > function Validator(){ > > > this.target; > > > } > > > Validator.prototype.checkRequired = function( target ){ > > if( $j(target).fieldValue() != "" ){ > > > $j(target).siblings( ".inputrequirement" ).removeClass( "inputrequired" ); > > } > > else{ > > var thisClass = $j( this ).attr("class"); > > //check if it is required > > if( thisClass.match( /required/ ) ){ > > //if so, change the background to say so > > and update the text > > $j(target).siblings( ".inputrequirement" > > ).addClass("class", > > "inputrequired").html( "This is a required field" ); > > } > > } > > } > > > Validator.prototype.validateElement = function( target ){ > > //show the verifying icon > > $j(target).siblings( ".inputstatus" ).attr("class", > > "inputstatus > > inputverifying"); > > //check the input with the server > > $j.getJSON( REQUEST_PREFIX + "ValidateRequest", { > > name: > > $j(target).attr("name"), id : $j(target).attr("id") , value : > > $j(target).fieldValue() }, function( json ){ > > //valid input, change to confirmed and wipe > > out any error text, > > remove required indicator > > if( json.validated == "true" ){ > > $j(target).siblings( ".inputstatus" > > ).attr("class", "inputstatus > > inputconfirmed" ).html( "" ); > > } > > //error, update with error text and change > > the icon > > else{ > > $j(target).siblings( ".inputstatus" > > ).attr( "class", "inputstatus > > inputerror").html( json.error ); > > } > > this.checkRequired( target ); > > > }); > > } > > ________________________________ > > > It fails on the line about four lines above, > > "this.checkRequired(target);", producing "this.checkRequired is not a > > function" error in the firebug console. > > When the error is clicked it says: > > > this.checkRequired is not a function > > (no name)(Object validated=true)eventdelegation.j... (line 109) > > success()jquery.js (line 2780) > > onreadystatechange(7)jquery.js (line 2735) > > [Break on this error] this.checkRequired( target ); > > > Anyway I'm hoping this is an elementary mistake or something in my > > class structure and hopefully someone can point it out and save me a > > ton of time and headache. > > Also I apologize if this is not a proper subject for this discussion > > group, if so feel free to delete it. > > > Thanks for any assistance! > > Hugh