1

can anybody see the issue with the following code? My script continues, ignoring my check.

The code below is only a snippet of the code but this issue is in here somewhere after doing some debugging.

function validatePasswordMatch(string1, string2) {
    if (string1 != string2) {
       return false;
    } else {
       return true;
    }
}

var validatePasswordMatchFields = ["textbox2", "textbox3"];

if (validatePasswordMatch($("#" + validatePasswordMatchFields[0]).val(), $("#" + validatePasswordMatchFields[1]).val())) {
   (some code)
} else {
   return false;
}
9
  • 2
    Please change that to return string1 == string2;! Commented Jul 30, 2013 at 15:01
  • 1
    What does the HTML look like and do you get any errors? Commented Jul 30, 2013 at 15:01
  • Well if the some code runs then it means that the two values are equal. What else did you expect? Do you run it at the wrong time? What values do the two textboxes have? Commented Jul 30, 2013 at 15:03
  • alerting both strings would be a good start. Commented Jul 30, 2013 at 15:04
  • Ugh... if (boolean) { return false; } else { return true; }. Why do you even need this function? Just do if (expr1 == expr2) { some code } else { return false; } Commented Jul 30, 2013 at 15:09

1 Answer 1

1
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>stackoverflow</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    function validatePasswordMatch(string1, string2) {
      if (string1 !== string2) {
        return false;
      } else {
        return true;
      }
    }

    var validatePasswordMatchFields = ["textbox2", "textbox3"];
    $(document).on('click','button',function(){
      result = validatePasswordMatch($("#" + validatePasswordMatchFields[0]).val(), $("#" + validatePasswordMatchFields[1]).val())
    if (result) {
      alert("match")
    } else {
      alert("not match")
    }
    })

});
</script>
</head>
<body>
<input id="textbox2" type="text" placeholder="password">
<input id="textbox3" type="text" placeholder="password">
<button type="button" id="button">Click Me!</button> 
</html>
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.