views:

30

answers:

1

Hi Guys,

I use to populate Dropdown using javascript:

function populateDDL(ddl_id) {

var option_str = "";
var x;
for(x in datalist){

    option_str += " <asp:ListItem Value='" + datalist[x] + "' Text='" + datalist[x] + "'></asp:ListItem>"
}
var country_div = document.getElementById(ddl_id);
country_div.innerHTML = option_str;
}

This is sure the datalist is not empty and also Dropdown list populated perfectly..but dnt know why after clicking on my page add button I am not getting the selected value.

Thanks

A: 

You should use client side select list control rather than server control to whome you are trying to fill at client side. Its surprised ...

But you should use select control

function populateDDL(ddl_id) {

var option_str = "<select id='ddl_id'>";
var x;
for(x in datalist){

    option_str += " <option value='" + datalist[x] + "'>" + datalist[x] + "</option>";
}
option_str += "</select>";
var country_div = document.getElementById(ddl_id);
country_div.innerHTML = option_str;
}
Azhar
I already added a comment for Chris Suggestion.
BreakHead
ohh.... but if its also returns empty value then their may be some problem in its filling or did you check the page source that if value filed empty their or not ...
Azhar