I’ve been fiddling with some AJAX functionality at work lately, and was stuck for quite a while on a weird problem. All the input fields were blanked when clicking back into the app, meaning that we lost all the state the user had built up when they clicked out then came back.

It seemed odd to me, but not having done anything with AJAX in the past, I assumed that was normal until I went into research mode and found this outline of AJAX client side session information storage. Of course, that article didn’t help much at first, since it completely contradicted what I was seeing, but that contradiction eventually lead me to dig back through the code.

Anyway, for what it’s worth, it seems that input field values aren’t re-populated when clicking back into a page unless they are contained within a form.

For what it’s worth, having an input outside a form seems to be allowed by the HTML spec (or at least the W3C validator accepts it). In the long run I would have had to add a form to let the app fall-back when there was no javascript, but it looks like I would have saved a bunch of time if I’d done it upfront.