Question: I'm kind of new at JS but I can't believe I've been unable to figure this out...

myerr is defined globally.
I set myerr=to the returned value from the post.
Once I get outside the function it looses it's value.

```
myerr="";
$.post("/rpc/validate_song_entry", {'title':$('#title').val()}, function(data){
  alert(data.title); //----> Alerts expected result.
  myerr=data.title;
  alert(myerr); //-----> Alerts expected result.
}, "json");
alert(myerr); //-------> Nothing. Blank dialog.

```

It seems to me it's a variable scope issue but I can't see how...

Edit:
I posted this below but don't know how to delete it...
I now understand that the post is done asynchronously. This makes sense. What does not make sense is that the alerts pop up in the order you see. I would expect the last alert (blank one) to appear first. It does not. It appears last.

I would expect the alerts inside the post function to appear last. Can anyone explain this?

Answer: 
It is because the post is done **asynchronously**. You will have to use $.ajax for your issue and set it to to asynchronous.

//edit: Also have a look at that: [Using $.post within a javascript function, cannot assign value to a variable?](https://stackoverflow.com/questions/824431/using-post-within-a-javascript-function-cannot-assign-value-to-a-variable)
function inside $.post(...) executes AFTER as it's done asynchronously. Your alert(myerr) executes right away before myerr was set.