Roger Withnell wrote:
[snip]
When the function is called with onblur, it works in IE but not in Safari or
NN. The function is called but the focus() and select() methods fail.
Something stupid I'm doing, I'll be bound.
[snip]
First, I *hate* things that trap me - with your form, the
user can't escape until they meet your criterion for the
textarea and enter zero to three characters. The event will
keep firing every time the box goes in and out of focus, so
if I change to another application, your alert keeps poping
up when I return to the browser.
So, please think carefully if there is some other (kinder)
way to do what you want.
The following is in regard to Firefox, but I suspect the
same is true for NN and Safari...
If you use an external button to run your script, it works
as expected - the alert pops up and when dismissed, the text
in the text area is selected. Incidentally, there is no
need to call focus(), select() will set focus on the
selected text (same for IE 6).
However, when run using onblur, closing the alert does not
seem to return focus to the textarea. When I subsequently
click on the textarea, it is selected for a moment, then a
cursor is placed in the text roughly where I clicked.
This indicates that the textarea content is not selected
until I put focus back on the textarea - but now it must
deal with the click, so it un-selects the text and puts
focus where the click occured. Perhaps execution of the
select is stopped until focus is returned to the textbox?
If I change to another application, then return to Firefox,
the text is selected. So it seems the "onblur" does not
really finish until the document or window loses focus.
Also, if I put focus on the textarea then change
applications, the onblur fires twice so I have to deal with
two alerts.
I tried a few work arounds, they were all messy and very
unsatisfactory. I'd just avoid this altogether and validate
the textarea on some other event.
Rob.