Sto eseguendo una convalida del modulo lato client per verificare se le password corrispondono. Ma la funzione di convalida restituisce sempre undefined
.Restituzione di un valore booleano in una funzione JavaScript
function validatePassword(errorMessage)
{
var password = document.getElementById("password");
var confirm_password = document.getElementById("password_confirm");
if(password.value)
{
// Check if confirm_password matches
if(password.value != confirm_password.value)
{
return false;
}
}
else
{
// If password is empty but confirm password is not
if(confirm_password.value)
{
return false;
}
}
return true;
}
Si prega di notare che il validatePassword
è chiamato da una funzione membro dell'oggetto Form.
function Form(validation_fn)
{
// Do other stuff
this.submit_btn = document.getElementById("submit");
this.validation_fn = validation_fn;
}
Form.prototype.submit = funciton()
{
var result;
if(this.validation_fn)
{
result = this.validation_fn();
}
//result is always undefined
if(result)
{
//do other stuff
}
}
Questa funzione non restituirà mai 'indefinito'. Si prega di definire * "è chiamato da una funzione membro dell'oggetto Form". * –
basta premere CTRL + MAIUSC + J - verificare se l'errore Se sì, postare qui, se non è necessario aprire il debugger ed eseguirlo. –
@AnilShanbhag Non restituisce alcun errore. Ho aperto il debugger e quando passo il codice, è quando ho capito che il risultato è stato impostato come 'undefined' – tryurbest