select

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

    select

    Est-il possible en javascript de modifier les OPTION d'une balise SELECT a
    partir d'un autre..? Donc la selection d'un premier choix changera la liste
    du deuxieme.

    Merci Alex...

    Is this possible in javascript to modify the OPTION of an SELECT from an
    other one..? So the first selection change the second option list.

    Thank Alex...


  • Lasse Reichstein Nielsen

    #2
    Re: select

    "Alexandre Laplante" <alaplante@avio r.ca> writes:
    [color=blue]
    > Is this possible in javascript to modify the OPTION of an SELECT from an
    > other one..? So the first selection change the second option list.[/color]

    Yes.
    You can trigger on the change to the first select element using the
    onchange event handler. You can then change the contents of the second
    select element from this handler.

    To change all the options of a select element (here referenced by
    selectRef), you can do something like

    var newOptions = ["option1","valu e1","option2"," value2"];

    var optsRef = selectRef.optio ns;
    while (optsRef.length > 0) { // Delete the current options
    selectRef.remov e(optsRef[0]);
    }
    for (var i=0;i< newOptions.leng th;i+=2) {
    selectRef.add(n ew Option(newOptio ns[i],newOptions[i+1]),null);
    }

    That is, use "selectRef.remo ve" to remove an option and
    "selectRef.add( new Option(text,val ue),null)" to add a new option.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Spiderman

      #3
      Re: select

      yep :P
      "Alexandre Laplante" <alaplante@avio r.ca> wrote in message
      news:%nDQa.4149 8$PD3.250689@nn rp1.uunet.ca...[color=blue]
      > Est-il possible en javascript de modifier les OPTION d'une balise SELECT a
      > partir d'un autre..? Donc la selection d'un premier choix changera la[/color]
      liste[color=blue]
      > du deuxieme.
      >
      > Merci Alex...
      >
      > Is this possible in javascript to modify the OPTION of an SELECT from an
      > other one..? So the first selection change the second option list.
      >
      > Thank Alex...
      >
      >[/color]


      Comment

      • Real Gagnon

        #4
        Re: select

        > Est-il possible en javascript de modifier les OPTION d'une balise[color=blue]
        > SELECT a partir d'un autre..? Donc la selection d'un premier choix
        > changera la liste du deuxieme.[/color]

        Pour un exemple :
        Real's HowTo : Useful code snippets for Java, JS, PB and more


        Bye.
        --
        Real Gagnon from Quebec, Canada
        * Looking for Java or PB snippets ? Visit Real's How-to
        * http://www.rgagnon.com/howto.html

        Comment

        Working...