Focus...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • geovanyayala@gmail.com

    Focus...

    How can i set the focus to one element on my page passing by parameters
    the form and the field...

    i search one function like this but y can`t find it...

    thanks for yoor help..

  • Daniel Kirsch

    #2
    Re: Focus...

    geovanyayala@gm ail.com wrote:[color=blue]
    > How can i set the focus to one element on my page passing by parameters
    > the form and the field...[/color]

    field.focus()

    Daniel

    Comment

    • Randy Webb

      #3
      Re: Focus...

      Daniel Kirsch wrote:[color=blue]
      > geovanyayala@gm ail.com wrote:
      >[color=green]
      >> How can i set the focus to one element on my page passing by parameters
      >> the form and the field...[/color]
      >[/color]

      function setFocus(formNa me,fieldName){

      if (document.forms[formName] &&
      document.forms[formName].elements[elementName] &&
      document.forms[formName].elements[elementName].focus)
      {
      document.forms[formName].elements[elementName].focus()
      }
      else{
      alert('Either the field or the form doesn't exist')
      }
      }
      [color=blue]
      > field.focus()[/color]

      Only if field is a fully qualified reference to the field. Otherwise it
      is an IE only solution.

      --
      Randy
      comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

      Comment

      • Art X

        #4
        Re: Focus...

        Randy Webb wrote:

        "
        function setFocus(formNa me,fieldName){
        if (document.forms[formName] &&
        document.forms[formName].elements[elementName] &&
        document.forms[formName].elements[elementName].focus)
        {
        document.forms[formName].elements[elementName].focus()
        }
        else{
        alert('Either the field or the form doesn't exist')
        }
        }
        "

        Can the dot notation used in this example be replaced with
        getElementById ?

        Later, Art.

        Comment

        • Daniel Kirsch

          #5
          Re: Focus...

          Randy Webb wrote:[color=blue]
          > Daniel Kirsch wrote:[color=green]
          >> field.focus()[/color]
          >
          >
          > Only if field is a fully qualified reference to the field. Otherwise it
          > is an IE only solution.[/color]

          Of course.

          Daniel

          Comment

          • Daniel Kirsch

            #6
            Re: Focus...

            Art X wrote:[color=blue]
            > Randy Webb wrote:
            >
            > "
            > function setFocus(formNa me,fieldName){
            > if (document.forms[formName] &&
            > document.forms[formName].elements[elementName] &&
            > document.forms[formName].elements[elementName].focus)
            > {
            > document.forms[formName].elements[elementName].focus()
            > }
            > else{
            > alert('Either the field or the form doesn't exist')
            > }
            > }
            > "
            >
            > Can the dot notation used in this example be replaced with
            > getElementById ?[/color]

            Only if the if of the element is known.

            function setFocus(fieldI D){
            var elm = document.getEle mentById(fieldI D);
            if (elm && typeof elm.focus == "function")
            elm.focus();
            }

            Daniel

            Comment

            • Daniel Kirsch

              #7
              Re: Focus...

              Daniel Kirsch wrote:[color=blue]
              > Only if the if of the element is known.[/color]

              Only if the *ID* of the element is known.

              Daniel

              Comment

              • Daniel Kirsch

                #8
                Re: Focus...

                Randy Webb wrote:[color=blue]
                > function setFocus(formNa me,fieldName){[/color]
                ^^^^^^^^^[color=blue]
                >
                > if (document.forms[formName] &&
                > document.forms[formName].elements[elementName] &&[/color]
                ^^^^^^^^^^^

                elementName should be fieldName

                Daniel

                Comment

                • Art X

                  #9
                  Re: Focus...

                  Daniel Kirsch wrote:

                  "Only if the *ID* of the element is known."

                  Great, I was concerned because I'm updating some of my pages with that.

                  Thanks Daniel and Randy for the replies and info.

                  Later, Art.

                  Comment

                  Working...