0

I'm attempting to call the msgs.loginUsername property, by dynamically grabbing "loginUsername" from the html with jQuery. However, I can't figure out how to structure the syntax to get it to work.

the object:

msgs = {
    loginUsername : "Username is required.",
    loginPassword : "Password is required."
};

the call:

function validateElements(_class) {
var errors = 0;
jQuery(_class).each(function() {
    if (!validate.required(this)) {
        var name = jQuery(this).attr('name'); //TROUBLE
        alert(msgs.name);                     //TROUBLE
        errors += 1;
    }
});
return errors > 0 ? false : true;
}

1 Answer 1

2

try using msgs[name] where name = "loginUsername" or "loginPassword"

function validateElements(_class) {
var errors = 0;
jQuery(_class).each(function() {
    if (!validate.required(this)) {
        var name = jQuery(this).attr('name'); //TROUBLE
        alert(msgs[name]);                     //TROUBLE
        errors += 1;
    }
});
return errors > 0 ? false : true;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.