www.webdeveloper.com
Results 1 to 5 of 5

Thread: How to prevent focus of a select object?

  1. #1
    Join Date
    Nov 2002
    Posts
    36

    How to prevent focus of a select object?

    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

  2. #2
    Join Date
    Nov 2002
    Location
    England
    Posts
    275
    Well I would have thought this would work:

    Code:
    <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

  3. #3
    Join Date
    Nov 2002
    Posts
    36
    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?


  4. #4
    Join Date
    Nov 2002
    Location
    England
    Posts
    275
    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.

  5. #5
    Join Date
    Dec 2011
    Posts
    1

    Tabindex

    Have you tried setting the TABINDEX="-1"?

    c.f.: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    Under Remarks:

    "3.Objects with a negative tabIndex are omitted from the tabbing order."

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles