Set focus problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Deidre

    #1

    Set focus problem

    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="vbscr ipt">
    Option Explicit
    ....other code
    If Not <%=mbReadOnly %> Then
    document.frmDet ails.txtName.fo cus()
    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
  • Ravikanth[MVP]

    #2
    Set focus problem

    Hi

    setfocus in body onload event,

    document.frmDet ails.txtName.fo cus()

    HTH
    Ravikanth

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

    Comment

    • Deidre

      #3
      Re: Set focus problem

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

      "Ravikanth[MVP]" <dvravikanth@ho tmail.com> wrote in message news:<0e1c01c34 d31$17c134a0$a3 01280a@phx.gbl> ...[color=blue]
      > Hi
      >
      > setfocus in body onload event,
      >
      > document.frmDet ails.txtName.fo cus()
      >
      > HTH
      > Ravikanth[/color]

      Comment

      • Deidre

        #4
        Re: Set focus problem

        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.frmDet ails.txtName.fo cus()
        End If
        End Sub

        Deidre

        Comment

        Working...