0

I am running this bit of code to check if a username is available or not.

It makes the error message appear but it doesn't change the variable

if(document.getElementById('username').value.length > 2) {
 v=$("#username");
 $.post('../action/checkusername.php',{username:v.val().toLowerCase()},function(d){
            if(d=='not-available'){
                iserror = iserror + 1;
                $('#warningbox').fadeIn("slow");    
                $('#usernamewarning2').show(); 
            } 
        });
}
Shantaram Tupe
  • 1,646
  • 3
  • 16
  • 42
Jexon
  • 23
  • 1
  • 7
  • *It makes the error message appear but it doesn't change the variable"* Yes, it does. What makes you think it doesn't? (My guess is [you're probably running into this](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call).) – T.J. Crowder Aug 05 '17 at 12:30
  • 2
    Two things: 1. When asking for help, please format your code consistently and readably (it's a good idea even when not asking for help). 2. Stack Snippets (the `[<>]` toolbar button you used) are for **runnable** examples. For just code blocks, like the above, use `{}` instead (or just indent by four spaces). A couple of us have fixed it for you this time. (An actual Snippet demonstrating the problem would have been good, though.) – T.J. Crowder Aug 05 '17 at 12:31
  • Please check if you have already declared the `iserror` variable before. Else when you are using `iserror = iserror + 1;` it will give _'Uncaught ReferenceError: iserror is not defined'_ and you will get nothing in that variable. – Sinha Aug 05 '17 at 12:36
  • 1
    Finally: Stack Overflow is a very active place, even on the weekend. When you post a question (or answer), *stick around* so you can reply to requests for clarification. I'm going to assume you're just looking at `isindex` before the `post` callback occurs. If that's not the case, edit the question to demonstrate the problem and I or another goldbadge can reopen it. – T.J. Crowder Aug 05 '17 at 12:38

0 Answers0