[thelist] Urgent HELP: [ADVANCED] How to prevent focus in a Combo Box (<select> tag) using JS?

Sheriff sheriff at drivestream.com
Tue Aug 30 04:11:56 CDT 2005


Hello to all JavaScript Experts out there,

I am having problems in preventing focus in a Combo Box, the
HTMLSelectElement. Before I could hear from you all, I would like to
list down the things that I tried myself, however, putting a word about
myself that I am an Advanced JavaScript developer.

I first tried writing all types of events handlers and did them return
false:

[code]
<script>

function evCboNoFocus(ev){
	if(!ev){
	  ev=window.event;
	  var el=ev.srcElement;	
	  ev.returnValue=false;
	} else {
	  var el=ev.target;
        ev.preventDefault();
	}
	el.blur();
	window.focus();
	return false;
}

window.onload=function(){
	// Get Element
	el=document.getElementById('cboCountry');
	//Register Events
	el.onmousedown=evCboNoFocus;
	el.onclick=evCboNoFocus;
	el.ondblclick=evCboNoFocus;
	el.onselect=evCboNoFocus;
	el.onselect=evCboNoFocus;
}

</script>
...
<select id="cboCountry">
...

[/code]

The result was not satisfactory :(.   The combo box still gains focus
for about 100ms or so and blurs... This means that the options are
listed for a while and disappear. This really frustrates the user if
suddenly a big list appears and disappears.

Background: I have a JS App which enabled users to click and drag form
elements and to be placed dynamically. I have *NO PROBLEMS* in the click
and drag code and stuff!

I have tested this behaviour in a separate page too.

My expected end result: My expectation is to get the Combo box to behave
smooth when the click and drag is performed. Also I *DO NOT* want to set
the disabled property, since it fades off the text and borders...

Any help is greatly appreciated!! :)

Thanks and Regards
Sheriff





More information about the thelist mailing list