Dynamically determine current field element?

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

    Dynamically determine current field element?

    Hi All,

    Is it possible to dynamically determine the current field element in a
    form?

    I ask because I have a 'tab' button on a form, and when a user clicks
    on it I need to be able to shift the focus to the next field, and also
    if the current field is the last field on the form, essentially to do
    nothing.

    Conceptually, I guess I'm trying to do something like:

    function clicktab(){

    variable = current.field.e lement.number;
    if (variable < n) {
    variable++;
    document.forms[0].element[variable].focus;
    }
    }

    In the above function, "n" would be the total number of fields in the
    form.

    I'd very much appreciate any assistance anyone can give!

    Much warmth,

    Murray
  • Bas Cost Budde

    #2
    Re: Dynamically determine current field element?

    M Wells wrote:
    [color=blue]
    > Hi All,
    >
    > Is it possible to dynamically determine the current field element in a
    > form?[/color]

    If you are willing to do some initializing, you can attach
    onfocus-handlers to every field, that write their tabIndex to a global
    variable. Then, on click of your tab button, you can increment the
    global variable and set focus on that element.

    Know how to proceed?
    --
    Bas Cost Budde


    Comment

    • Guy Roydor

      #3
      Re: Dynamically determine current field element?

      document.forms[0].length

      M Wells a écrit:[color=blue]
      > Hi All,
      >
      > Is it possible to dynamically determine the current field element in a
      > form?
      >
      > I ask because I have a 'tab' button on a form, and when a user clicks
      > on it I need to be able to shift the focus to the next field, and also
      > if the current field is the last field on the form, essentially to do
      > nothing.
      >
      > Conceptually, I guess I'm trying to do something like:
      >
      > function clicktab(){
      >
      > variable = current.field.e lement.number;
      > if (variable < n) {
      > variable++;
      > document.forms[0].element[variable].focus;
      > }
      > }
      >
      > In the above function, "n" would be the total number of fields in the
      > form.
      >
      > I'd very much appreciate any assistance anyone can give!
      >
      > Much warmth,
      >
      > Murray[/color]

      Comment

      • M Wells

        #4
        Re: Dynamically determine current field element?

        On Tue, 03 Feb 2004 10:26:43 +0100, Bas Cost Budde <bas@heuveltop. org>
        wrote:
        [color=blue]
        >M Wells wrote:
        >[color=green]
        >> Hi All,
        >>
        >> Is it possible to dynamically determine the current field element in a
        >> form?[/color]
        >
        >If you are willing to do some initializing, you can attach
        >onfocus-handlers to every field, that write their tabIndex to a global
        >variable. Then, on click of your tab button, you can increment the
        >global variable and set focus on that element.
        >
        >Know how to proceed?[/color]

        Hiya,

        What I'm wondering is if there's any way of retrieving the element
        number of the field.

        So, a way of knowing that document.forms[0].elements[5] currently has
        the focus, as opposed to document.forms[0].elements[6] etc.

        Much warmth,

        Murray

        Comment

        • Bas Cost Budde

          #5
          Re: Dynamically determine current field element?

          > What I'm wondering is if there's any way of retrieving the element[color=blue]
          > number of the field.
          >
          > So, a way of knowing that document.forms[0].elements[5] currently has
          > the focus, as opposed to document.forms[0].elements[6] etc.[/color]

          Without any action before? wishing "document.curre ntElement"?
          I doubt it, I couldn't find anything pointing in that direction when I
          searched. Can you put window.getSelec tion to use?

          --
          Bas Cost Budde


          Comment

          Working...