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

Reply via email to