It's a quick experience, it makes things great. But when JavaScript is disabled, I don't have the ability to run that form submit when I add that file. So if I disable JavaScript again, if I can locate my mouse, there we go, and reload this page, if I go to upload my file, when I upload it, it's going to turn into a little upload button, and when I click that, it's going to do the upload, process the file, and tell me that I have succeeded, and I can go back to my previous page. That's great.
How does it work? Pretty simple. We really just have another form. It's a very short section of DOM code, and this form has a handle submit, very like the other one, but it has an input that accepts a file, and when that file changes, if JavaScript's enabled, it's going to submit the form, and if JavaScript is not enabled, this handler will not be attached, this handler will not be attached, and what's going to happen is this button is going to be enabled, because we never got the chance to disable it with this browser variable, and when the file input becomes valid, and the button becomes not disabled, the button will appear, which gives us the ability to submit this form, which then redirects us to the other page.
So this works great, with or without JavaScript, and it only added a few lines of code. I don't have time to talk to you more about this, or I would, I could go on about it all day, but I really do hope that this has given you some philosophical questions to think about. Hopefully you can see that the philosophy of progressive enhancement, while it's definitely a mental shift from the implement everything in JavaScript philosophy, is not as difficult as it may seem on the surface. And the payoff is certainly worth it. Reaching more customers and having a site that's more resilient to technology failures will pay dividends in the long run. This code is available at github.com slash tccsejohnson slash lgtm. Feel free to contact me with questions on Twitter at underscore Gruntled, or by email at elliot.johnson at bursell.com.
Comments