[thelist] javascript input field focus/blur

Andrew Clover and at doxdesk.com
Mon Apr 22 12:54:00 CDT 2002


Stephane Deschamps <stephane.deschamps at francetelecom.com> wrote:

> Below is a JS function that is called onfocus="testBon()".

> My problem is that if you click on "Cancel" the confirm popup
> displays TWICE...

When a JS alert/confirm/query box opens, it takes the input focus.
When the box is closed, the element on the page that previously
had focus gets it back, which could generate an onfocus event again,
depending on what order the browser takes the refocus and your
blur() call.

I wouldn't do it like this. As well as the refocus problem, it will
really annoy keyboard users tabbing through the form fields. How
about storing the previous value of the field onfocus and generating
the prompt onchange. If 'cancel' is clicked you can then replace the
field with its previous value.

PS. document.forms['formName'].elements['formField'].value is a
    more robust way of referencing it.

--
Andrew Clover
mailto:and at doxdesk.com
http://and.doxdesk.com/



More information about the thelist mailing list