From the course: Ajax with PHP: Add Dynamic Content to Websites

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Disable form button

Disable form button

From the course: Ajax with PHP: Add Dynamic Content to Websites

Start my 1-month free trial

Disable form button

- [Instructor] In this movie we'll look at the third user experience improvement that we should always consider when submitting forms via Ajax. That is, we will disable the form button so that the form can't be submitted more than once. The process for disabling the button, and then re-enabling it later, is going to be similar to what we had for showSpinner. As soon as calculateMeasurements is called, before the Ajax request is even sent, we're going to make that button be disabled, and then once we get down here and we have a success, onreadystatechange equals to four, then we want to re-enable it, just like we are hiding the spinner again, and that will allow the user to then submit the form again. So we're only disabling it for the length of time it takes to get a request back. So let's write our code right here to disable the button. Now we've already found the button down here at the bottom of our page, you'll remember we added an EventListener for it down here. So I'm going to…

Contents