Element Focus on Body load

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

    #1

    Element Focus on Body load

    Trying to set the focus to an element of input type on loading the page.
    This is the code I used but it doesn't work. Any suggestions? (IE 6,
    Windows)

    <SCRIPT language=JavaSc ript>
    funcion setFocus() {
    document.formna me.fieldname.on focus();
    }
    </SCRIPT>

    <BODY onload="setFocu s()">

    Thanks,
    Mica


  • Jerry Park

    #2
    Re: Element Focus on Body load

    Mica Cooper wrote:[color=blue]
    > Trying to set the focus to an element of input type on loading the page.
    > This is the code I used but it doesn't work. Any suggestions? (IE 6,
    > Windows)
    >
    > <SCRIPT language=JavaSc ript>
    > funcion setFocus() {
    > document.formna me.fieldname.on focus();
    > }
    > </SCRIPT>
    >
    > <BODY onload="setFocu s()">
    >
    > Thanks,
    > Mica
    >
    >[/color]
    Well, the setFocus() routine should say
    document.formna me.fieldname.fo cus(), but why not just say that in the
    onload statement?

    Comment

    • Mica Cooper

      #3
      Re: Element Focus on Body load

      Jerry,

      Many thanks. I was using JavaScript Bible by Danny Goodman and it lists on
      the bottom of page 66 document.formna me.fieldname.on focus();
      as the proper way to give a field focus. Thank you for correcting me.

      You are correct that I could do it in the onLoad but there are sometimes
      more than one thing so I actually use and init() in the onLoad that would
      call the setFocus method.

      Thanks Again,
      Mica Cooper

      "Jerry Park" <NoReply@No.Spa m> wrote in message
      news:SmJBb.2788 $Y83.752@bignew s2.bellsouth.ne t...[color=blue]
      > Mica Cooper wrote:[color=green]
      > > Trying to set the focus to an element of input type on loading the page.
      > > This is the code I used but it doesn't work. Any suggestions? (IE 6,
      > > Windows)
      > >
      > > <SCRIPT language=JavaSc ript>
      > > funcion setFocus() {
      > > document.formna me.fieldname.on focus();
      > > }
      > > </SCRIPT>
      > >
      > > <BODY onload="setFocu s()">
      > >
      > > Thanks,
      > > Mica
      > >
      > >[/color]
      > Well, the setFocus() routine should say
      > document.formna me.fieldname.fo cus(), but why not just say that in the
      > onload statement?[/color]


      Comment

      • @SM

        #4
        Re: Element Focus on Body load

        Mica Cooper a ecrit :
        [color=blue]
        > Trying to set the focus to an element of input type on loading the page.
        > This is the code I used but it doesn't work. Any suggestions? (IE 6,
        > Windows)
        >
        > <SCRIPT language=JavaSc ript>
        > funcion setFocus() {
        > document.formna me.fieldname.on focus();[/color]

        // it is not 'onfocus' but 'focus'
        document.forms['formname'].elements['fieldname'].focus();
        [color=blue]
        >
        > }[/color]

        onload=setFocus ;
        [color=blue]
        >
        > </SCRIPT>
        >
        > <BODY onload="setFocu s()">[/color]

        onload in tag BODY is no more authorised (I think ...)


        --
        *************** *************** *************** *************** **
        Stéphane MORIAUX : mailto:stephane OTER-MOImoriaux@wana doo.fr
        Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)

        *************** *************** *************** *************** **


        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Element Focus on Body load

          "Mica Cooper" <mica_cooper@mi crocore.net> writes:
          [color=blue]
          > Many thanks. I was using JavaScript Bible by Danny Goodman and it lists on
          > the bottom of page 66 document.formna me.fieldname.on focus();
          > as the proper way to give a field focus. Thank you for correcting me.[/color]

          I would recommend using:
          document.forms['formname'].elements['fieldname'].focus();
          That is also correct according to the W3C DOM, as well as backwards
          compatible with all (JS-enabled) browsers.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Mica Cooper

            #6
            Re: Element Focus on Body load

            Hey backward compatibility.
            I'll do that. Appreciate the tip.

            "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
            news:isko19y4.f sf@hotpop.com.. .[color=blue]
            > "Mica Cooper" <mica_cooper@mi crocore.net> writes:
            >[color=green]
            > > Many thanks. I was using JavaScript Bible by Danny Goodman and it lists[/color][/color]
            on[color=blue][color=green]
            > > the bottom of page 66 document.formna me.fieldname.on focus();
            > > as the proper way to give a field focus. Thank you for correcting me.[/color]
            >
            > I would recommend using:
            > document.forms['formname'].elements['fieldname'].focus();
            > That is also correct according to the W3C DOM, as well as backwards
            > compatible with all (JS-enabled) browsers.
            >
            > /L
            > --
            > Lasse Reichstein Nielsen - lrn@hotpop.com
            > DHTML Death Colors:[/color]
            <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>[color=blue]
            > 'Faith without judgement merely degrades the spirit divine.'[/color]


            Comment

            Working...