Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable keyboard in HTML SELECT tag

I want to disable the keyboard for an HTML SELECT tag so the user can only use a mouse to select the options.

I've tried event.cancelBubble=true on the onkeydown, onkeyup and onkeypress events with no luck.

Any ideas?

like image 591
Oundless Avatar asked Oct 26 '22 03:10

Oundless


1 Answers

In a cross-browser way assuming that the event object has been properly initialized:

function disableKey(e)
{
   var ev = e ? e : window.event;

   if(ev)
   {
       if(ev.preventDefault)
          ev.preventDefault();
       else
         ev.returnValue = false;         
   }    
}
like image 87
xdevel2000 Avatar answered Nov 15 '22 13:11

xdevel2000