Automatically click a field

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

    #1

    Automatically click a field

    Hi,
    can I have a field automatically clicked by calling something like
    click()?
    I have a dropdown box, one of whose elements is "Others (Please
    Specify)". I list the dropdown boxes values alphabetically.
    Sometimes, this value happens to be on the top and SELECTED. The problem
    is that if this item is selected by clicking on it, in response to
    onChange I open a text field (so user can specify the value). If this
    field is automatically selected, the text field des not show; I have to
    select another value then click on the "Other (please Specify)" to have
    the text field visible.

    Thanx.


  • Ivo

    #2
    Re: Automatically click a field

    "Xerxes" wrote[color=blue]
    > Hi,
    > can I have a field automatically clicked by calling something like
    > click()?[/color]

    Yes. Newer browsers implement that method for a variety of elements as the
    references can tellyou.
    [color=blue]
    > I have a dropdown box, one of whose elements is "Others (Please
    > Specify)". I list the dropdown boxes values alphabetically.
    > Sometimes, this value happens to be on the top and SELECTED. The problem
    > is that if this item is selected by clicking on it, in response to
    > onChange I open a text field (so user can specify the value).[/color]

    The problem is you rely on an onchange while sometimes there is none. Create
    a dummy option, with a title text and no value, on top, so that one is
    selected when there is none selected.

    HTH
    Ivo
    [color=blue]
    > If this
    > field is automatically selected, the text field des not show; I have to
    > select another value then click on the "Other (please Specify)" to have
    > the text field visible.
    >
    > Thanx.
    >
    >[/color]


    Comment

    • Xerxes

      #3
      Re: Automatically click a field

      Thanks Ivo.
      The problem with creating a dummy value is that the values of the
      dropdown box are set by querying a database, sorted alphabetically. If I
      use something like "Select something...", it might fall somewhere in the
      middle of the list of values. Any way I can get around it? Can I assign
      an index (of zero) to an option?

      <SELECT>
      <options are filled in from a database in a php file>
      < option index=0 (??)>Make a selection</option>
      </select>

      Thanks.

      "Ivo" <no@thank.you > wrote in message
      news:40ad7861$0 $60777$cd19a363 @news.wanadoo.n l...[color=blue]
      > "Xerxes" wrote[color=green]
      > > Hi,
      > > can I have a field automatically clicked by calling something like
      > > click()?[/color]
      >
      > Yes. Newer browsers implement that method for a variety of elements as[/color]
      the[color=blue]
      > references can tellyou.
      >[color=green]
      > > I have a dropdown box, one of whose elements is "Others (Please
      > > Specify)". I list the dropdown boxes values alphabetically.
      > > Sometimes, this value happens to be on the top and SELECTED. The[/color][/color]
      problem[color=blue][color=green]
      > > is that if this item is selected by clicking on it, in response to
      > > onChange I open a text field (so user can specify the value).[/color]
      >
      > The problem is you rely on an onchange while sometimes there is none.[/color]
      Create[color=blue]
      > a dummy option, with a title text and no value, on top, so that one is
      > selected when there is none selected.
      >
      > HTH
      > Ivo
      >[color=green]
      > > If this
      > > field is automatically selected, the text field des not show; I have[/color][/color]
      to[color=blue][color=green]
      > > select another value then click on the "Other (please Specify)" to[/color][/color]
      have[color=blue][color=green]
      > > the text field visible.
      > >
      > > Thanx.
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Ivo

        #4
        Re: Automatically click a field

        "Xerxes" wrote[color=blue]
        > Thanks Ivo.
        > The problem with creating a dummy value is that the values of the
        > dropdown box are set by querying a database, sorted alphabetically. If I
        > use something like "Select something...", it might fall somewhere in the
        > middle of the list of values. Any way I can get around it? Can I assign
        > an index (of zero) to an option?[/color]

        Silly you! Can't you add the first option after the sorting has taken place?
        Like with line no. 2 added to your code below:

        1. > <SELECT>
        2. <option value="">Look Ma, no sorting.
        3. > <options are filled in from a database in a php file>
        4. > </select>

        If you need to have the options in an PHP array before anything else, have a
        look at www.php.net/array_unshift.
        HTH
        Ivo


        Comment

        • Mick White

          #5
          Re: Automatically click a field

          Xerxes wrote:
          [color=blue]
          > Hi,
          > can I have a field automatically clicked by calling something like
          > click()?
          > I have a dropdown box, one of whose elements is "Others (Please
          > Specify)". I list the dropdown boxes values alphabetically.
          > Sometimes, this value happens to be on the top and SELECTED. The problem
          > is that if this item is selected by clicking on it, in response to
          > onChange I open a text field (so user can specify the value). If this
          > field is automatically selected, the text field des not show; I have to
          > select another value then click on the "Other (please Specify)" to have
          > the text field visible.
          >
          > Thanx.
          >[/color]

          <script type="text/JavaScript">
          function replaceOptionWi thPrompt(menu,m sg){
          if(menu.selecte dIndex==menu.le ngth-1){
          var x=window.prompt (msg,"");
          if(x){
          menu[menu.length-1]= new Option(x,x);
          menu[menu.length-1].selected=true;
          }
          }
          }
          </script>

          <form>
          <select name="jobs" onchange="repla ceOptionWithPro mpt(this,'Pleas e
          supply your job description')">
          <option selected>Profes sion</option>
          <option value="doc">Doc tor</option>
          <option value="atty">La wyer</option>
          <option value="realtor" >Real Estate</option>
          <option value="other">O ther</option>
          </select>
          </form>

          Mick

          Comment

          Working...