I have a contact form with a submit button. I am using JQuery to do the following in exactly the following order once a response is received from the server-side PHP that processes the submitted data:
- Change button text to "Send"
- Display the received response in an alert
The code is straightforward:
submit_button.text('Send');
alert(response);
However, the alert()
always seems to trigger before the text change no matter what. Is this by design? Any trick to alter the sequence? I need the button's text to change before the alert is displayed. I even tried the following in vain:
submit_button.text('Send');
if(submit_button.text() == 'Send') { alert(response); }
I'm sorry if this question has already been answered elsewhere and request you to point me in the right direction should that be the case.