Click here to Skip to main content
15,905,566 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So i have a very little challenge. In the Database, i'm retrieving a a value for each user(Note: the values are not the same). For example, user A might have value 2, while User B might have user 3. What i want to do is create a dropdown control with select values corresponding to the value of each user. So if user B logs in, three dropdown will be displayed while if its user A, two dropdown will be displayed. I want to create this dropdown dynamically. Ho do i achieve this using Jquery ?

What I have tried:

What i have done is to write the query to fetch the number for each user. What is left is to be able to display number of dropdown depending on the value of each user
Posted
Updated 19-Jul-17 2:15am
v2
Comments
Karthik_Mahalingam 19-Jul-17 5:33am    
3 dropdown controls or a single dropdown with different options?
Mcbaloo 19-Jul-17 5:43am    
The number of dropdowns is dependent on the value assigned to each user in the database
Karthik_Mahalingam 19-Jul-17 5:47am    
and the values to each dropdown?
Mcbaloo 19-Jul-17 6:07am    
i will bind them with values from database. i think i can find a way round binding values to the dropdown once i can create the dropdown control dynamically.
Karthik_Mahalingam 19-Jul-17 6:43am    
create dropdown dynamically using ajax and jquery?

1 solution

The first google result has a good example. See How to create dropdown list dynamically using jQuery? - Stack Overflow[^]

var data = {
    'foo': 'bar',
    'foo2': 'baz'
}


var s = $('<select />');

for(var val in data) {
    $('<option />', {value: val, text: data[val]}).appendTo(s);
}

s.appendTo('body'); // or wherever it should be


In this case, data may be coming from a webservice call using jQuery's .ajax() method.
 
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