Skip to content
Advertisement

Synchronous javascript: How to continue script after input value is set?

I have this javascript:

JavaScript

I need to execute the line with status--; only after $('#input').val(base64); on the previous line is securely finished.

Is there some simple solution?

Advertisement

Answer

What makes you think, it doesn’t? The UI might not be updated yet because JS runs on the browsers UI thread and thus, the UI thread is blocked while the JS is still running, but the input does have the correct value internally.

JavaScript
JavaScript

So if you really want to continue only after the UI is updated, you need to make for instance a timeout (can even be zero) to return to the browsers UI thread, which will update the UI and then take the next js from the eventloop.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement