How can I select the content of select tag if the values are viewed by JavaScript?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Exequiel
    Contributor
    • Jul 2012
    • 288

    #1

    How can I select the content of select tag if the values are viewed by JavaScript?

    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <script type="text/javascript">
    function ikel()
    {
        var sel = document.ikki.sel.value;
     
        if(sel=="T-shirt")
        {         
            var shirt = ["bench","cotton republic"];
            var shirt_len=shirt.length;
            var el=0;
            for(var ii=0; ii<shirt_len; ii++)
            {
                 document.ikki.brand.options[ii]=new Option(shirt[ii], ii);            
                }
            return sel;
        }//end of if satatement T-shirt
     
        if(sel=="CARS")
        {         
            var car = ["Toyota","Honda", "Forbes", "Mitsubishi", "Kia", "Nissan"];
            var car_len=car.length;
            var cc=0;
            for(var cc=0; cc<car_len; cc++)
            {
                 document.ikki.brand.options[cc]=new Option(car[cc], cc);            
                }
             return sel;
        }//end of if satatement Cars
     
        if(sel=="Porn Site")
        {         
            var por = ["Mofos.com","Naughty America.com", "Erotica.com"];
            var por_len=por.length;
            var xx=0;
            for(var xx=0; xx<por_len; xx++)
            {
                 document.ikki.brand.options[xx]=new Option(por[xx], xx);            
                }
            return sel; 
        }//end of if satatement Cars
     
    }//end of function ikel
    window.onload=ikel;
    </script>
    </head>
    <body>
    <form name="ikki">
    Menu
            <select name="sel"  onclick="ikel()" id="selected" >
                       <option >T-shirt</option>
                       <option >CARS</option>
                       <option >Porn Site</option> 
                 </select> 
              Brand              
                  <select name="brand" onchange="ikel()" ><!--option output--></select> 
    </form>
    </body>
    </html>
    I have A question... How can I select the content of brand here...Example : when I selected in the Menu like for Example CARS, the Options will display in "Brand", but when I started to select the 2nd to the last option in Brand, the only value that appears is the first value like "Toyota"...
Working...