views:

395

answers:

1

Hi there!

I'm a newbie in js and I'm afraid that i haven't the knowledge to resolve the next issue.

If I have a select element ( populated with several options ) already parsed by the browser on the load, the next code works just fine in both IE and FF

$('selectId').focus();

but if I create ( and populate it ) the element via js

var select = new Element('select',{ 'id':'selectId' });
~ etc. with options ~
select.focus();

the focus event doesn't work in IE. With FF is everything OK!

I've already tried various methods to workaround this issue but without good results! Every time I need to click on the element to activate the focus event ( in IE ).

( yes, I use the mootools library! )

Any help will be very appreciated!

Thank you!

A: 

@Christoff Thank you my friend! I'm afraid that I must use the ver 1.11 of mootools because the project is based on the latest version of Joomla ( 1.5.14 ) which supports only the 1.11 mootools... I've tried to call the click event right after the creation of the element ( as you have done in the sample ) and it seems to work, not 100%, but works. The only issue is if you click the FIRST option, right after the appearance of the select, you'll get at the alert the value of the pre-selected! If you click any other option, the alert returns the right value! Strange! ( I always talk for the IE7-8 browser! )

Also, I copy-pasted the code from the mooshel to the jsbin.com ( http://jsbin.com/axuxi ) and it seems to have the same problem. The first click always return the value of the pre-selected...

Thank you for the help!

George
perhaps you are handling the wrong event here. i NEVER get the first option - in FF 3.5 and ie7. however, i suppose it is conceivable that the click event itself may fire before the onchange event, similarly to how onkeydown or onkeypress do. i refactored things a little here http://mooshell.net/tnYBY/ - through onfocus and onchange. it works reliably imo, but you may get the function run twice (for example, if you have lost focus, then click on a new option). p.s. you need firebug / console to see this, or replace with alerts..
Dimitar Christoff