By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,476 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

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

Exequiel
100+
P: 288
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Untitled Document</title>
  4. <script type="text/javascript">
  5. function ikel()
  6. {
  7.     var sel = document.ikki.sel.value;
  8.  
  9.     if(sel=="T-shirt")
  10.     {         
  11.         var shirt = ["bench","cotton republic"];
  12.         var shirt_len=shirt.length;
  13.         var el=0;
  14.         for(var ii=0; ii<shirt_len; ii++)
  15.         {
  16.              document.ikki.brand.options[ii]=new Option(shirt[ii], ii);            
  17.             }
  18.         return sel;
  19.     }//end of if satatement T-shirt
  20.  
  21.     if(sel=="CARS")
  22.     {         
  23.         var car = ["Toyota","Honda", "Forbes", "Mitsubishi", "Kia", "Nissan"];
  24.         var car_len=car.length;
  25.         var cc=0;
  26.         for(var cc=0; cc<car_len; cc++)
  27.         {
  28.              document.ikki.brand.options[cc]=new Option(car[cc], cc);            
  29.             }
  30.          return sel;
  31.     }//end of if satatement Cars
  32.  
  33.     if(sel=="Porn Site")
  34.     {         
  35.         var por = ["Mofos.com","Naughty America.com", "Erotica.com"];
  36.         var por_len=por.length;
  37.         var xx=0;
  38.         for(var xx=0; xx<por_len; xx++)
  39.         {
  40.              document.ikki.brand.options[xx]=new Option(por[xx], xx);            
  41.             }
  42.         return sel; 
  43.     }//end of if satatement Cars
  44.  
  45. }//end of function ikel
  46. window.onload=ikel;
  47. </script>
  48. </head>
  49. <body>
  50. <form name="ikki">
  51. Menu
  52.         <select name="sel"  onclick="ikel()" id="selected" >
  53.                    <option >T-shirt</option>
  54.                    <option >CARS</option>
  55.                    <option >Porn Site</option> 
  56.              </select> 
  57.           Brand              
  58.               <select name="brand" onchange="ikel()" ><!--option output--></select> 
  59. </form>
  60. </body>
  61. </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"...
Jul 12 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.