Returning a boolean value in a JavaScript function

I am doing a client side form validation to check if passwords match. But the validation function always returns `undefined`. 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; } Please note that the `validatePassword` is called from a member function of the Form object. 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 } }
This function will never return undefined. Please define "is called from a member function of the Form object."

以上就是Returning a boolean value in a JavaScript function的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准