Click to See Complete Forum and Search --> : How to prevent focus of a select object?
Doug_Dyer
11-24-2002, 04:18 PM
Anyone know how to prevent the focus of the SELECT guy?
I want to disable it, but the disabled=true blurs out the text.
I currently have an ONFOCUS event handler that checks my criteria and calls element.focus() or element.blur().
This works for the textboxes but not SELECT.
Any help would be appreciated!
Thanks,
Doug
Rick Bull
11-24-2002, 04:55 PM
Well I would have thought this would work:
<select onfocus="this.blur();">
not sure why it doesn't (if that's what you had). But remember not everyone has JavaScript enabled, so using the disabled attribute is a more compatible way of doing it.
EDIT: having re-read it I get the impression you're setting the disabled attribute through JS anyway, so my last comments was a bit pointless :D
Doug_Dyer
11-24-2002, 07:58 PM
Well I am using IE 5.0+ on win2000. Id have thought this.blur() would have worked. Try it, I sure cant get it going :(
Turns out the only way to prevent modification without disabling (which affects visibility) is to REDIRECT the focus! And not only that you have to replace several methods:
<select onmousedown="blah(this);" ondblclick="blah(this);" onfocus="blah(this);">
(Can't remember the exact spelling of the onmousedown method)
blah(element)
{
if (my criteria to prevent changes == true)
nextelement.focus();
}
Incidentally, if given an element, is there a quick way to get the next element or previous element in the form element array?
Rick Bull
11-25-2002, 04:58 AM
You're right it doesn't work in IE, although it does work in Opera and Mozilla, so I can only put it down to a bug with events and <select>. I did think of returning false onfocus/click/mousedown but that doesn't work either. Not sure about the next/prev elements thing, sorry.
i_cypher
12-30-2011, 01:56 PM
Have you tried setting the TABINDEX="-1"?
c.f.: http://msdn.microsoft.com/en-us/library/ms534654(v=vs.85).aspx
Under Remarks:
"3.Objects with a negative tabIndex are omitted from the tabbing order."