Set focus back after form submit (javascript)
===

I have some input fields on my form that require submit on change. When they are submitted I lose the focus. I want to have my focus back on my input. I wanted to use that:

    Event.observe(document, 'dom:loaded', $('" + focusedFieldId + "').focus());

where focusedFieldId is id of changed element. Sometimes it works fine but sometimes I got null value in my input. When I change focusedFieldId to some other field id it works fine (it sets the value and then focus on field). The problem is only when I try set focus back on the same input. One important issue: after value change some javascript is fired (http://www.devbridge.com/projects/autocomplete/prototype/). After this javascript form is submitted and then I want to set focus back. I thought that when dom is loaded it means that submit is over, page is reloaded and I'm ready to set focus back. Where do I make wrong?