0

I want to use a input parameter of a javascript function inside jquery command.

function logInEmail(value){
    var ati = $("input[name=" + this.value + "]").val();
    if(ati.length == 0){
        alert("Email cant be empty");
        return false;
    }else{
        return true;
    }
}

What is the best way to do it?

user1684140
  • 424
  • 5
  • 17

2 Answers2

2

Since you've assigned value as the logInEmail function parameter, you can use:

var ati = $("input[name=" + value + "]").val();

instead of:

var ati = $("input[name=" + this.value + "]").val();
Felix
  • 37,443
  • 7
  • 40
  • 55
0

Remove "this" in javascript parameter variable as given below (value instead of this.value).

function logInEmail(value){
    var ati = $("input[name=" + value + "]").val();
    if(ati.length == 0){
        alert("Email cant be empty");
        return false;
    }else{
        return true;
    }
}
svjn
  • 884
  • 2
  • 18
  • 35