Set focus problem

D

Deidre

I have a page with a drop down and several web controls. The drop down
is set to postback and it reloads the textboxes based on the selected
drop down item. I set the focus to the first textbox control on the
client like this:
<script language="vbscript">
Option Explicit
....other code
If Not <%=mbReadOnly%> Then
document.frmDetails.txtName.focus()
End If
....other code
</script>
This works fine on first page load but when I change the drop down it
does reset the focus and you can't even type in the first textbox
until you select another textbox first.
To debug I added a message box right before the set focus to see if it
was even getting to this line of code and it works but I can't leave a
message box here.
Any ideas on what could be the problem?
Thanks in advance for any help,
Deidre
 
R

Ravikanth[MVP]

Hi

setfocus in body onload event,

document.frmDetails.txtName.focus()

HTH
Ravikanth
 
D

Deidre

Thanks for the suggestion but it does the same thing if I put it in a
body onload event.
 
D

Deidre

I fixed my problem. I needed to move my set focus command to the window_onload sub:
Sub Window_OnLoad()
If Not <%=mbReadOnly%> Then
document.frmDetails.txtName.focus()
End If
End Sub

Deidre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top