0

I would like to compare the status of a variable "feedback" against a string 'Not Available'.

I'm able to console.log the value of the variable and it displays Not Available, yet, If statement logic is not displaying "username already in use"

var feedback = $("#feedback").text();
console.log("feedback status is:" + feedback);
if (feedback === 'Not Available') {
    console.log("Username already in use!");
    e.preventDefault();
};
2
  • 1
    First of all the e.preventDefault() is wrong. What supposed that does ? And can you please provide us with the exact output of the console.log ? Commented Feb 25, 2015 at 16:37
  • 1
    How about posting a complete code example? Commented Feb 25, 2015 at 16:41

3 Answers 3

3

may be your variable value contains extra spaces, try using $.trim(), as:

if ( $.trim(feedback) === 'Not Available' ) {
   ...
}
Sign up to request clarification or add additional context in comments.

Comments

1

Use localeCompare()

if (feedback.localeCompare('Not Available')) {

Comments

0

Please show your console result.So we can get idea of actually what getting from your variable.

Try variableName. toLowerCase() to remove case sensitive issues.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.