Text box has no focus

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

    Text box has no focus

    I have a text box, on my form that I cant get the focus on. I'm using it as
    shown:
    <head>
    <body onload=document .getPassword.tx tPasswordName.f ocus()>
    </head>

    Where
    getPassword is the form &
    txtPasswordName is the text box

    Why is this? Anyone know a better way of doing this?


  • McKirahan

    #2
    Re: Text box has no focus

    " JCO" <J.Oliviero@ver izon.net> wrote in message
    news:UVjWb.4513 $1B6.1175@nwrdd c03.gnilink.net ...[color=blue]
    > I have a text box, on my form that I cant get the focus on. I'm using it[/color]
    as[color=blue]
    > shown:
    > <head>
    > <body onload=document .getPassword.tx tPasswordName.f ocus()>
    > </head>
    >
    > Where
    > getPassword is the form &
    > txtPasswordName is the text box
    >
    > Why is this? Anyone know a better way of doing this?[/color]


    You probably can't use "onload=" as the form isn't loaded.

    Remove "onload=" and add the following at the end of the page:

    <script type="text/javascript">
    document.getPas sword.txtPasswo rdName.focus();
    </script>


    Comment

    • Randy Webb

      #3
      Re: Text box has no focus

      McKirahan wrote:[color=blue]
      > " JCO" <J.Oliviero@ver izon.net> wrote in message
      > news:UVjWb.4513 $1B6.1175@nwrdd c03.gnilink.net ...
      >[color=green]
      >>I have a text box, on my form that I cant get the focus on. I'm using it[/color]
      >
      > as
      >[color=green]
      >>shown:
      >><head>
      >><body onload=document .getPassword.tx tPasswordName.f ocus()>
      >></head>
      >>
      >>Where
      >>getPassword is the form &
      >>txtPasswordNa me is the text box
      >>
      >>Why is this? Anyone know a better way of doing this?[/color]
      >
      >
      >
      > You probably can't use "onload=" as the form isn't loaded.[/color]

      Since onload events only happen after the document is loaded (thats what
      its for), then the form is indeed loaded.


      OP:
      One major problem, and may/may not be part of the source of the problem,
      is that the body tag goes after the </head> tag, the body is not part of
      the head section. Although most browsers error correct soup code and
      close the head when it encounters the body tag. Validate HTML before
      complaining about javascript.

      It also will depend on whether getPassword is the name or the id of the
      form (It matters). Same for txtPasswordName .

      Validate your code, after its valid, if it still doesn't set focus, post
      the minimum code (or a URL) to the offending page.

      --
      Randy
      Chance Favors The Prepared Mind
      comp.lang.javas cript FAQ - http://jibbering.com/faq/

      Comment

      • JCO

        #4
        Re: Text box has no focus

        Yes the form name is getPassword and the text box name is txtPasswordName .
        As shown:

        <FORM NAME="getPasswo rd" onSubmit="retur n GetUserInput()" >
        <p align="center"> &nbsp;<INPUT TYPE="password" NAME="txtPasswo rdName"
        VALUE="" SIZE=14>&nbsp;
        <input type="reset" value="Clear" name="btnClear" ></p>
        <p align="center"> Enter Password</p>

        Base on this form, the onload is as shown:
        <body onload=document .getPassword.tx tPasswordName.f ocus()>

        Also, an important thing to note, the focus is set correctly when I preview
        it in the browser. It does not work after the site is published.

        Thanks again for the inputs!



        "Randy Webb" <hikksnotathome @aol.com> wrote in message
        news:DY6dnTGriY cdvrfdRVn-vg@comcast.com. ..[color=blue]
        > McKirahan wrote:[color=green]
        > > " JCO" <J.Oliviero@ver izon.net> wrote in message
        > > news:UVjWb.4513 $1B6.1175@nwrdd c03.gnilink.net ...
        > >[color=darkred]
        > >>I have a text box, on my form that I cant get the focus on. I'm using[/color][/color][/color]
        it[color=blue][color=green]
        > >
        > > as
        > >[color=darkred]
        > >>shown:
        > >><head>
        > >><body onload=document .getPassword.tx tPasswordName.f ocus()>
        > >></head>
        > >>
        > >>Where
        > >>getPassword is the form &
        > >>txtPasswordNa me is the text box
        > >>
        > >>Why is this? Anyone know a better way of doing this?[/color]
        > >
        > >
        > >
        > > You probably can't use "onload=" as the form isn't loaded.[/color]
        >
        > Since onload events only happen after the document is loaded (thats what
        > its for), then the form is indeed loaded.
        >
        >
        > OP:
        > One major problem, and may/may not be part of the source of the problem,
        > is that the body tag goes after the </head> tag, the body is not part of
        > the head section. Although most browsers error correct soup code and
        > close the head when it encounters the body tag. Validate HTML before
        > complaining about javascript.
        >
        > It also will depend on whether getPassword is the name or the id of the
        > form (It matters). Same for txtPasswordName .
        >
        > Validate your code, after its valid, if it still doesn't set focus, post
        > the minimum code (or a URL) to the offending page.
        >
        > --
        > Randy
        > Chance Favors The Prepared Mind
        > comp.lang.javas cript FAQ - http://jibbering.com/faq/
        >[/color]


        Comment

        • JCO

          #5
          Re: Text box has no focus

          Nothing I do, puts the cursor in the text box. Seems strange.
          I tried moving the onLoad to the bottom .. below the creation of the form.
          It made no difference so I put it back at the beginning of the body.

          Still not working!

          "Randy Webb" <hikksnotathome @aol.com> wrote in message
          news:DY6dnTGriY cdvrfdRVn-vg@comcast.com. ..[color=blue]
          > McKirahan wrote:[color=green]
          > > " JCO" <J.Oliviero@ver izon.net> wrote in message
          > > news:UVjWb.4513 $1B6.1175@nwrdd c03.gnilink.net ...
          > >[color=darkred]
          > >>I have a text box, on my form that I cant get the focus on. I'm using[/color][/color][/color]
          it[color=blue][color=green]
          > >
          > > as
          > >[color=darkred]
          > >>shown:
          > >><head>
          > >><body onload=document .getPassword.tx tPasswordName.f ocus()>
          > >></head>
          > >>
          > >>Where
          > >>getPassword is the form &
          > >>txtPasswordNa me is the text box
          > >>
          > >>Why is this? Anyone know a better way of doing this?[/color]
          > >
          > >
          > >
          > > You probably can't use "onload=" as the form isn't loaded.[/color]
          >
          > Since onload events only happen after the document is loaded (thats what
          > its for), then the form is indeed loaded.
          >
          >
          > OP:
          > One major problem, and may/may not be part of the source of the problem,
          > is that the body tag goes after the </head> tag, the body is not part of
          > the head section. Although most browsers error correct soup code and
          > close the head when it encounters the body tag. Validate HTML before
          > complaining about javascript.
          >
          > It also will depend on whether getPassword is the name or the id of the
          > form (It matters). Same for txtPasswordName .
          >
          > Validate your code, after its valid, if it still doesn't set focus, post
          > the minimum code (or a URL) to the offending page.
          >
          > --
          > Randy
          > Chance Favors The Prepared Mind
          > comp.lang.javas cript FAQ - http://jibbering.com/faq/
          >[/color]


          Comment

          • mscir

            #6
            Re: Text box has no focus

            JCO wrote:[color=blue]
            > Nothing I do, puts the cursor in the text box. Seems strange.
            > I tried moving the onLoad to the bottom .. below the creation of the form.
            > It made no difference so I put it back at the beginning of the body.
            >
            > Still not working![/color]

            Try the approach google uses (view source - relevant code shown).

            <html>
            <head>
            <title>Google </title>
            <script>
            <!--
            function sf(){document.f .q.focus();}
            // -->
            </script>
            </head>
            <body onLoad=sf()>
            <form action="/search" name=f>
            <input maxLength=256 size=55 name=q value="">
            </body>
            </html>
            [color=blue]
            >
            > "Randy Webb" <hikksnotathome @aol.com> wrote in message
            > news:DY6dnTGriY cdvrfdRVn-vg@comcast.com. ..
            >[color=green]
            >>McKirahan wrote:
            >>[color=darkred]
            >>>" JCO" <J.Oliviero@ver izon.net> wrote in message
            >>>news:UVjWb.4 513$1B6.1175@nw rddc03.gnilink. net...
            >>>
            >>>
            >>>>I have a text box, on my form that I cant get the focus on. I'm using[/color][/color]
            >
            > it
            >[color=green][color=darkred]
            >>>as
            >>>
            >>>
            >>>>shown:
            >>>><head>
            >>>><body onload=document .getPassword.tx tPasswordName.f ocus()>
            >>>></head>
            >>>>
            >>>>Where
            >>>>getPasswo rd is the form &
            >>>>txtPassword Name is the text box
            >>>>
            >>>>Why is this? Anyone know a better way of doing this?
            >>>
            >>>
            >>>
            >>>You probably can't use "onload=" as the form isn't loaded.[/color]
            >>
            >>Since onload events only happen after the document is loaded (thats what
            >>its for), then the form is indeed loaded.
            >>
            >>
            >>OP:
            >>One major problem, and may/may not be part of the source of the problem,
            >>is that the body tag goes after the </head> tag, the body is not part of
            >>the head section. Although most browsers error correct soup code and
            >>close the head when it encounters the body tag. Validate HTML before
            >>complaining about javascript.
            >>
            >>It also will depend on whether getPassword is the name or the id of the
            >>form (It matters). Same for txtPasswordName .
            >>
            >>Validate your code, after its valid, if it still doesn't set focus, post
            >>the minimum code (or a URL) to the offending page.
            >>
            >>--
            >>Randy
            >>Chance Favors The Prepared Mind
            >>comp.lang.jav ascript FAQ - http://jibbering.com/faq/[/color][/color]

            Comment

            • JCO

              #7
              Re: Text box has no focus

              Yes, I tried it exactly as you explained and I also looked at the Google
              site to read their code.
              It is still not working.

              Could it have anything to do with the type of text box?
              Below is the exact code that I'm using:




              <body>
              ...... other stuff

              <!-- jco; This creates a form that contains a text field and 2-buttons to
              validate users input -->
              <FORM NAME="frmPasswo rd" onEnter="return valForm()">
              <!-- jco; Add two buttons and a text field -->
              <p align="center">
              <input type=password name="txtInput" size="28" onkeypress="onE nter();" ></p>
              <p align="center">
              <input type="button" value="Enter Password" name="btnEnter"
              onclick="valFor m();">&nbsp;&nb sp;
              <input type="reset" value="Clear" name="btnClear" ></p>
              </form>

              <!-- jco; Setfocus to text box so user can quickly sign in -->
              <body onload=document .frmPassword.tx tInput.focus()>

              </body>

              Note:
              I just moved the onload to the bottom. Now it works, however, the cursor
              keeps blinking. There is animaiton on the top frame. The cursor seems to
              blink with the animation.

              Should I move the line of code back to the top; Before the form?
              Or should I manage the blinking ... somehow?




              "mscir" <mscir@access4l ess.net> wrote in message
              news:102nr00s8v aq122@corp.supe rnews.com...[color=blue]
              > JCO wrote:[color=green]
              > > Nothing I do, puts the cursor in the text box. Seems strange.
              > > I tried moving the onLoad to the bottom .. below the creation of the[/color][/color]
              form.[color=blue][color=green]
              > > It made no difference so I put it back at the beginning of the body.
              > >
              > > Still not working![/color]
              >
              > Try the approach google uses (view source - relevant code shown).
              >
              > <html>
              > <head>
              > <title>Google </title>
              > <script>
              > <!--
              > function sf(){document.f .q.focus();}
              > // -->
              > </script>
              > </head>
              > <body onLoad=sf()>
              > <form action="/search" name=f>
              > <input maxLength=256 size=55 name=q value="">
              > </body>
              > </html>
              >[color=green]
              > >
              > > "Randy Webb" <hikksnotathome @aol.com> wrote in message
              > > news:DY6dnTGriY cdvrfdRVn-vg@comcast.com. ..
              > >[color=darkred]
              > >>McKirahan wrote:
              > >>
              > >>>" JCO" <J.Oliviero@ver izon.net> wrote in message
              > >>>news:UVjWb.4 513$1B6.1175@nw rddc03.gnilink. net...
              > >>>
              > >>>
              > >>>>I have a text box, on my form that I cant get the focus on. I'm using[/color]
              > >
              > > it
              > >[color=darkred]
              > >>>as
              > >>>
              > >>>
              > >>>>shown:
              > >>>><head>
              > >>>><body onload=document .getPassword.tx tPasswordName.f ocus()>
              > >>>></head>
              > >>>>
              > >>>>Where
              > >>>>getPasswo rd is the form &
              > >>>>txtPassword Name is the text box
              > >>>>
              > >>>>Why is this? Anyone know a better way of doing this?
              > >>>
              > >>>
              > >>>
              > >>>You probably can't use "onload=" as the form isn't loaded.
              > >>
              > >>Since onload events only happen after the document is loaded (thats what
              > >>its for), then the form is indeed loaded.
              > >>
              > >>
              > >>OP:
              > >>One major problem, and may/may not be part of the source of the problem,
              > >>is that the body tag goes after the </head> tag, the body is not part of
              > >>the head section. Although most browsers error correct soup code and
              > >>close the head when it encounters the body tag. Validate HTML before
              > >>complaining about javascript.
              > >>
              > >>It also will depend on whether getPassword is the name or the id of the
              > >>form (It matters). Same for txtPasswordName .
              > >>
              > >>Validate your code, after its valid, if it still doesn't set focus, post
              > >>the minimum code (or a URL) to the offending page.
              > >>
              > >>--
              > >>Randy
              > >>Chance Favors The Prepared Mind
              > >>comp.lang.jav ascript FAQ - http://jibbering.com/faq/[/color][/color]
              >[/color]


              Comment

              • mscir

                #8
                Re: Text box has no focus

                JCO wrote:
                [color=blue]
                > Yes, I tried it exactly as you explained and I also looked at the Google
                > site to read their code. It is still not working.
                >
                > Could it have anything to do with the type of text box?
                > Below is the exact code that I'm using:
                >
                > <FORM NAME="frmPasswo rd" onEnter="return valForm()">
                > <p align="center">
                > <input type=password name="txtInput" size="28" onkeypress="onE nter();" ></p>
                > <p align="center">
                > <input type="button" value="Enter Password" name="btnEnter"
                > onclick="valFor m();">&nbsp;&nb sp;
                > <input type="reset" value="Clear" name="btnClear" ></p>
                > </form>
                > <body onload=document .frmPassword.tx tInput.focus()>
                > ...
                > </body>
                >
                > Note:
                > I just moved the onload to the bottom. Now it works, however, the cursor
                > keeps blinking. There is animaiton on the top frame. The cursor seems to
                > blink with the animation.
                >
                > Should I move the line of code back to the top; Before the form?
                > Or should I manage the blinking ... somehow?[/color]

                2 questions:

                - Do you have two <body> tags?
                - Are you unhappy because the cursor blinks in the text box, or with the
                RATE of blinking?

                Not sure why this didn't work when you left the body tag where it
                belongs, just following the <head> section:

                <body onload=document .frmPassword.tx tInput.focus()>

                Maybe it has something to do with other code on the page.

                How about you post your page somewhere where folks can view it? If you
                don't have a site to publish it to you can easily get a free Geocities
                web space after creating a Yahoo email account.

                Mike

                Comment

                • JCO

                  #9
                  Re: Text box has no focus

                  I only have one body tag such as:
                  <body>
                  ....table stuff here
                  ....form is loaded here, then
                  <body onload=document .frmPassword.tx tInput.focus()>
                  </body>

                  The blinking is not consistent. It has the normal cursor blink, which is
                  okay, then every so often the blinking is interfered with by something else.
                  It is hard to explain. What is weird is that it all works fine when I
                  preview it.

                  I will let you know when I get it posted...thanks


                  "mscir" <mscir@access4l ess.net> wrote in message
                  news:102qeg2q6d car7c@corp.supe rnews.com...[color=blue]
                  > JCO wrote:
                  >[color=green]
                  > > Yes, I tried it exactly as you explained and I also looked at the Google
                  > > site to read their code. It is still not working.
                  > >
                  > > Could it have anything to do with the type of text box?
                  > > Below is the exact code that I'm using:
                  > >
                  > > <FORM NAME="frmPasswo rd" onEnter="return valForm()">
                  > > <p align="center">
                  > > <input type=password name="txtInput" size="28" onkeypress="onE nter();"[/color]
                  ></p>[color=green]
                  > > <p align="center">
                  > > <input type="button" value="Enter Password" name="btnEnter"
                  > > onclick="valFor m();">&nbsp;&nb sp;
                  > > <input type="reset" value="Clear" name="btnClear" ></p>
                  > > </form>
                  > > <body onload=document .frmPassword.tx tInput.focus()>
                  > > ...
                  > > </body>
                  > >
                  > > Note:
                  > > I just moved the onload to the bottom. Now it works, however, the[/color][/color]
                  cursor[color=blue][color=green]
                  > > keeps blinking. There is animaiton on the top frame. The cursor seems[/color][/color]
                  to[color=blue][color=green]
                  > > blink with the animation.
                  > >
                  > > Should I move the line of code back to the top; Before the form?
                  > > Or should I manage the blinking ... somehow?[/color]
                  >
                  > 2 questions:
                  >
                  > - Do you have two <body> tags?
                  > - Are you unhappy because the cursor blinks in the text box, or with the
                  > RATE of blinking?
                  >
                  > Not sure why this didn't work when you left the body tag where it
                  > belongs, just following the <head> section:
                  >
                  > <body onload=document .frmPassword.tx tInput.focus()>
                  >
                  > Maybe it has something to do with other code on the page.
                  >
                  > How about you post your page somewhere where folks can view it? If you
                  > don't have a site to publish it to you can easily get a free Geocities
                  > web space after creating a Yahoo email account.
                  >
                  > Mike
                  >[/color]


                  Comment

                  • mscir

                    #10
                    Re: Text box has no focus

                    JCO wrote:
                    [color=blue]
                    > I only have one body tag such as:
                    > <body>
                    > ...table stuff here
                    > ...form is loaded here, then
                    > <body onload=document .frmPassword.tx tInput.focus()>
                    > </body>
                    >
                    > The blinking is not consistent. It has the normal cursor blink, which is
                    > okay, then every so often the blinking is interfered with by something else.
                    > It is hard to explain. What is weird is that it all works fine when I
                    > preview it.
                    >
                    > I will let you know when I get it posted...thanks[/color]

                    I'd recommend you remove the "<body onload..." line and use this approach:

                    Network Solutions - Original domain name registration and reservation services with variety of internet-related business offerings. Quick, dependable and reliable.


                    <form>
                    ...all of the form code goes above this javascript...

                    <script type="text/javascript">
                    // set focus to form field
                    document.forms[0].MyFormFieldNam e.focus();
                    document.forms[0].MyFormFieldNam e.select();
                    </script>
                    </form>

                    Comment

                    • Randy Webb

                      #11
                      Re: Text box has no focus

                      mscir wrote:
                      [color=blue]
                      > JCO wrote:
                      >[color=green]
                      >> I only have one body tag such as:
                      >> <body>
                      >> ...table stuff here
                      >> ...form is loaded here, then
                      >> <body onload=document .frmPassword.tx tInput.focus()>
                      >> </body>
                      >>
                      >> The blinking is not consistent. It has the normal cursor blink, which is
                      >> okay, then every so often the blinking is interfered with by something
                      >> else.
                      >> It is hard to explain. What is weird is that it all works fine when I
                      >> preview it.
                      >>
                      >> I will let you know when I get it posted...thanks[/color]
                      >
                      >
                      > I'd recommend you remove the "<body onload..." line and use this approach:
                      >
                      > http://www.projectseven.com/tutorial...rmfldfocus.htm
                      >
                      > <form>
                      > ...all of the form code goes above this javascript...
                      >
                      > <script type="text/javascript">
                      > // set focus to form field
                      > document.forms[0].MyFormFieldNam e.focus();
                      > document.forms[0].MyFormFieldNam e.select();
                      > </script>
                      > </form>
                      >[/color]

                      And if its not the first form on the page?

                      document.forms['formName'].elements['elementName'].focus();
                      document.forms['formName'].elements['elementName'].select();

                      Now it doesn't matter anymore.

                      but if it won't focus directly from the onload, set the onload to a
                      function and call it onload.

                      --
                      Randy
                      Chance Favors The Prepared Mind
                      comp.lang.javas cript FAQ - http://jibbering.com/faq/

                      Comment

                      • JCO

                        #12
                        Re: Text box has no focus

                        This is working. Thanks!
                        Sorry we had to go back n forth so many times when it ended up to be 2-lines
                        of code.
                        Again, thanks.

                        ----- Original Message -----
                        From: "Randy Webb" <hikksnotathome @aol.com>
                        Newsgroups: comp.lang.javas cript
                        Sent: Saturday, February 14, 2004 11:35 AM
                        Subject: Re: Text box has no focus

                        "Randy Webb" <hikksnotathome @aol.com> wrote in message
                        news:YZmdnZ-RZdZgP7PdRVn-hA@comcast.com. ..[color=blue]
                        > mscir wrote:
                        >[color=green]
                        > > JCO wrote:
                        > >[color=darkred]
                        > >> I only have one body tag such as:
                        > >> <body>
                        > >> ...table stuff here
                        > >> ...form is loaded here, then
                        > >> <body onload=document .frmPassword.tx tInput.focus()>
                        > >> </body>
                        > >>
                        > >> The blinking is not consistent. It has the normal cursor blink, which[/color][/color][/color]
                        is[color=blue][color=green][color=darkred]
                        > >> okay, then every so often the blinking is interfered with by something
                        > >> else.
                        > >> It is hard to explain. What is weird is that it all works fine when I
                        > >> preview it.
                        > >>
                        > >> I will let you know when I get it posted...thanks[/color]
                        > >
                        > >
                        > > I'd recommend you remove the "<body onload..." line and use this[/color][/color]
                        approach:[color=blue][color=green]
                        > >
                        > > http://www.projectseven.com/tutorial...rmfldfocus.htm
                        > >
                        > > <form>
                        > > ...all of the form code goes above this javascript...
                        > >
                        > > <script type="text/javascript">
                        > > // set focus to form field
                        > > document.forms[0].MyFormFieldNam e.focus();
                        > > document.forms[0].MyFormFieldNam e.select();
                        > > </script>
                        > > </form>
                        > >[/color]
                        >
                        > And if its not the first form on the page?
                        >
                        > document.forms['formName'].elements['elementName'].focus();
                        > document.forms['formName'].elements['elementName'].select();
                        >
                        > Now it doesn't matter anymore.
                        >
                        > but if it won't focus directly from the onload, set the onload to a
                        > function and call it onload.
                        >
                        > --
                        > Randy
                        > Chance Favors The Prepared Mind
                        > comp.lang.javas cript FAQ - http://jibbering.com/faq/
                        >[/color]


                        Comment

                        Working...