clearing list

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

    clearing list

    Hi

    I'm working on a site that has a form on it to do an advanced search on
    a database, in the form are 2 list (<select>)

    Both these list have items in them, what I want to do is if an items it
    selected from list A then it sets list B value to null and of cause the
    other way round. The reason is I need to make sure that when the
    form is submitted I only pass an item from either list A or B not both
    is I do a test on each variable to see what has been selected

    I have tried onChange="this. form.town.value =''"

    any ideas?

    Brian



  • RobG

    #2
    Re: clearing list

    Brian wrote:[color=blue]
    > Hi
    >
    > I'm working on a site that has a form on it to do an advanced search on
    > a database, in the form are 2 list (<select>)
    >
    > Both these list have items in them, what I want to do is if an items it
    > selected from list A then it sets list B value to null and of cause the
    > other way round. The reason is I need to make sure that when the
    > form is submitted I only pass an item from either list A or B not both
    > is I do a test on each variable to see what has been selected
    >
    > I have tried onChange="this. form.town.value =''"
    >
    > any ideas?[/color]

    Use an onchange function on each list that sets the other to a default
    empty option (or has some value you know to ignore).

    <form action="">
    <select name="listA" onchange="this. form.listB.sele ctedIndex=0;">
    <option selected></option>
    <option value="A1">A1</option>
    <option value="A2">A2</option>
    </select>
    <select name="listB" onchange="this. form.listA.sele ctedIndex=0;">
    <option selected></option>
    <option value="B1">B1</option>
    <option value="B2">B2</option>
    </select>
    </form>



    --
    Rob

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: clearing list

      Brian wrote:
      [color=blue]
      > [...] The reason is I need to make sure that when the form is submitted I
      > only pass an item from either list A or B not both is I do a test on each
      > variable to see what has been selected[/color]

      Note that it does not work without client-side script support:
      [color=blue]
      > I have tried onChange="this. form.town.value =''"[/color]

      If `town' is the name of a select control, this is not supposed to work.
      The `value' attribute/property of those objects only specifies the selected
      value. Use this instead:

      var o = selectElement.o ptions;
      if ((o.length = 0) > 0)
      {
      while (o.length > 0)
      {
      o[0] = null;
      }
      }


      PointedEars
      --
      Let us not judge others because of their religion, color or nationality.
      We are all just human beings living together on this planet. (poehoe.de)

      Comment

      Working...