Dynamic dropdown

Discussion in 'JavaScript' started by praba230890, Aug 13, 2011.

  1. #1
    I have two dropdowns in my site. I want to change the number of options and the values of options of one dropdown depending on the value we choosing on the other dropbox by 'onChange()' fn using JavaScript. For example
    /*first dropdown*/
    <select name="language" id="language">
    <option>select</option>
    <option >English</option>
    <option>Tamil</option>
    <option>Telugu</option>
    <option >Kannada</option>
    <option>Malayalam</option>
    <option >Urdu</option>
    <option>Punjabi</option>
    </select>

    /*Second dropdown whose no of options & values are to be changed based on changing the value of above dropdown*/
    <select name="media">
    <option>The Indian Express</option>
    <option >The Hindu</option>
    <option >CNN IBN</option>
    <option>NDTV</option>

    </select>


    I was struggling with it for a long and even if this can be done through php please provide me a solution.
     
    praba230890, Aug 13, 2011 IP
  2. programmer_best1

    programmer_best1 Well-Known Member

    Messages:
    282
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    133
    #2
    ok here we go... now your main dropdown menu id is "language", so that is what you need to do:-
    
    document.getElementById("language"). location.href="youfilename.php?action=" + document.getElementById("section").value; } 
    
    Code (markup):
    so that js code will reload your php file, and you will get new php $_GET variable with the main dropdown menu value.
    $Acrion = $_GET['action'];
    and now all what you need to do is to put if statement for the 2nd dropmenu by using the new $Action variable which include the 1st menu value.

    good luck :)
     
    programmer_best1, Aug 15, 2011 IP