[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Focus method not working
Greetings everybody:
I sent this message yesterday and noticed the last half of my message
was cut off. Sorry! I am having problems with using the focus method in
a function that is suppose to validate a field. I have had good luck with
using the focus method to set my cursor to a specific field on an onLoad
function I have, but when I try to put the focus method in my validate function
it doesn't work. Here is the validate function:
<SCRIPT LANGUAGE=JavaScript>
function validate_uid(obj) {
if (obj.value.length != 6) {
alert("\nInvalid ID Length. \nPlease enter a 6 character UID.\n");
obj.focus();
obj.select();
}
}
</SCRIPT>
I have tried to use both the onBlur and onChange event on the UID field.
<input type="text" name="user_id" size=25 onChange="validate_uid(this)">
The alert works, the select works, but the focus doesn't. For example, I enter
'12' in the UID field and hit TAB, the function gives me the alert, selects
the text, but lets the cursor go to the next field. I tried this using
Navigator for Windows 95, Windows NT, and SunOS. It worked on the Mac.
Any advice?
-- Jeff
-----------------------------------------------------------------
Jeffrey Hunter | EMAIL: jhunter@llnl.gov
Computer Scientist | PHONE: (510) 423-0271
Lawrence Livermore National Laboratory | FAX : (510) 422-2384
P.O. Box 808, L-434 |
Livermore, CA 94551 |
-----------------------------------------------------------------