vendredi 26 février 2016

How to change option by selecting different values in javascript

I have two condition, if i am selecting no.1 from the drop down list then i want to see option 1 and if i am selecting no.2 from the drop down list then i want to see option 2.

     var mylist=document.getElementById("mylist");

         if(mylist.value == "1")
           {
            document.getElementById('myalllist').getElementsByTagName('option')[1].selected = 'selected';
           }
         if (mylist.value == "2")
          {

            document.getElementById('myalllist').getElementsByTagName('option')[2].selected = 'selected';
          }


  HTML

    <select id="mylist" onchange="fndropoption()">
     <option>Select</option>
     <option>1</option>
     <option>2</option>
   </select>       

    <select id="myalllist" onchange="fndropoption()">
     <option value="1">xxxxxxxx</option> 
     <option value="2">yyyyyyyy</option>
    </select>

SO, If i select 1 from my dropdown list, then option[1] should appear on my next drop down list and if i select 2 from dropdown list, then option[2] should appear on my next drop down list

Aucun commentaire:

Enregistrer un commentaire