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
  • 444
  • 6
  • 18

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,892
  • 8
  • 43
  • 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
  • 904
  • 2
  • 19
  • 35