cancel
Showing results for 
Search instead for 
Did you mean: 

focus for an element on popup

Former Member
0 Kudos

Hi friends,

I am having a textfield and an applet on a popup window.I need to set focus for that text box, as and when popup window opens.As applet is taking time to load, the textbox is loosing its focus.I had used applet events like creation,firstupdation and even used settimeout function but still it's not working.Is there anyway in which i can stop executing the javascript until entire html page loads.

regards,

Ravi Kumar

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Ravi,

I have tried this in the past with success:

setTimeout("document.getElementbyID('txtField').focus()",2000)

Give this a try...play around with the numberical value (2000) which is in milliseconds until you get something that works.

THank You,

A.P.

Former Member
0 Kudos

Hi Alin,

I had tried to check whether it's working or not by increasing the time to 10 sec.But in my page the applet loading is getting stopped while i set timeout.

So it's not getting focussed still.

Regards,

Ravi Kumar.

Former Member
0 Kudos

Ravi,

I just tested this and it should not be affecting your applet. Are you setting the timeout on the whole function call executing your applet or just the line which sets the focus???

In my test i had two text boxes one which gets a value assigned on load and the other 3 seconds later. The execution of the latter piece of code was done first and then the timeout codeset was executed.

Give me some more insight into how you have your code setup.

Former Member
0 Kudos

Hi Alin,

My page consists of an iGrid applet and a text box.

On page load i need to set focus for that text box which i am unable to nw.

Actually what happening is that as the applet loads the focus is shifting from text box to applet.

I can test it because if i press tab button on page load the text box is getting its focus again.

Regards,

Ravi Kumar

Former Member
0 Kudos

Have you tried using the "FirstUpdateEvent" on the applet to fire off a function to set the focus ???

Former Member
0 Kudos

Hi,

I had tried using firstupdateevent also but it's not working.I had tried even by hiding the applet initially and set the focus and make the applet visible later.Until the applet becomes visible, the focus stays inside the text box, and after that focus shifts to iGrid applet.

Regards,

Ravi Kumar.

Former Member
0 Kudos

Hi Ravi,

Have you already tried the body onload event? I assume that you have.

Using the body onload event is ok if you want to control form elements and such (like setting focus of a text box). You'll want to avoid the onload to synchronize applet loading; instead, use the applet events.

I have seen in the past where focus was set and something else took it away quicker than the eye could pick it up. I don't remember the exact details of that scenario, but my "fix" was to set focus to the field twice.

document.getElementById("txtField").focus();

document.getElementById("txtField").focus();

And if I remember correctly, this double command was only need in IE. It worked fine in Firefox. Perhaps it has to do with the annoying feature of IE where the applet needs to be clicked before you can use it.

jcgood25
Active Contributor
0 Kudos

Another trick I've used is to use .focus() followed by .select() , which still is the double IE correction but if the text field has a default value in it then it is automatically highlighted for convenient editing.

Regards,

Jeremy

Former Member
0 Kudos

Hi Ryan,

It's same way happening here.As the popup window loads i can see the cursor inside the text box,but as applet finishes to load, it's just loosing it's focus.

regards,

Ravi Kumar

Former Member
0 Kudos

what if you do the second focus or select via an update or creation event of the applet?

Former Member
0 Kudos

Hi Ryan,

It's not working even if i focused the element twice.I had already used applet update and creation event of the applet.Actually i can see cursor position inside the text box for a fraction of second.But after that it's off from the textbox.

Regards,

Ravi Kumar