Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi all,
I am new to JavaScript and trying but don't know how to do....
My question is how to display option in dropdownlist dynamically using JavaScript.

Can anybody help me in this regard ?
Posted
Updated 27-Jul-14 20:08pm
v2
Comments
Do you want to show selected option in a alert box?
SRS(The Coder) 28-Jul-14 2:06am    
can you please paste your html here and elaborate more what exactly you want ?

function LoadValues(){
removeAllOptions(document.drop_list.ddlName);
addOption(document.drop_list.ddlName, " ", "--Select--");

if(If WE want Add Any Condition We can Add Else Simply Skip if Part)
{
addOption(document.drop_list.ddlName,"value1", "Text1");
addOption(document.drop_list.ddlName,"value2", "Text2");
addOption(document.drop_list.ddlName,"value3", "Text3");
}
else if(Condition)
{
addOption(document.drop_list.ddlName,"value1", "Text1");
addOption(document.drop_list.ddlName,"value2", "Text2");
addOption(document.drop_list.ddlName,"value3","Text3");

}




Santhosh
 
Share this answer
 
Add options for sources:
<select id="sources"></select>

function showSources(values) {
    var sources = document.getElementById('sources');
    var option;

    var count = values.length;
    if (count == 0) {
        option = document.createElement('option');
        option.text = "N/A";
        sources.appendChild(option);
    }
    else {
        for (var i = 0; i < count; i++) {
            option = document.createElement('option');
            option.text = values[i];
            sources.appendChild(option);
        };
    }
}
 
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