I have a form, user enters some data then submits. Rather than a popup window or going to a new page, I used an “invisible” iframe so that the page wont refresh. If everything goes smoothly then the iframe should remain invisible. But if the servlet throws an error I want that error to show in the iframe, that iframe should resize itself to maybe 2-300px.
Is this possible?
Assuming that this is all on the same domain, you should Ajax instead. I recommend using jQuery to simplify this task: http://api.jquery.com/category/ajax/
You could do something like this:
Your code should be more robust than this (maybe using JSON instead of a status string), but it’s a good start.
If you want to show the error, then
alertit (like in the example), or use a dialog. Doing it like this is unobtrusive and easily maintainable (since iframes are not fun to use).Iframes are generally frowned upon, especially invisible ones.