Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all, I use the following code to dynamically create option control in java script. If I execute this code 5 times, this will create 5 drop down list with values. How can I get the selected value of each drop down list on its selected event.


C#
var myCars = ["Full Physical",
      "Light Physical",
      "Gesture", "Verbal",
      "Independent"];
    var i = 1;
    var cellRight = row.insertCell(1);
    var el = document.createElement('select');
    el.type = 'select';
    el.name = 'select' + i;
    el.id = 'optRow' + iteration;
    


    el.size = 1;
    for (var key in myCars)
    {


        //alert();
        var option = document.createElement("option");
        option.text = myCars[key];
        option.name = step_value;
        option.id = myCars[key].id;


        //option.value = key.value;
        try
        {
            el.add(option, null); //Standard
        } catch (error) {
            el.add(option); // IE only
        }
    }
    cellRight.appendChild(el);
    
    i = i + 1;

}
Posted

Add this code before this line el.size = 1; & you will get idea

el.onchange=function(){alert(el.name);};
 
Share this answer
 
C#
el.onchange = function ()
                {

                    var sdValues = document.getElementById(el.id);
                    var strUser = sdValues.options[sdValues.selectedIndex].value;
                    
                };
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900