I’ve created a page and manage to get data to the select list from a JSON file, but when I enter the page I cannot see the value chosen unless I click the list. (See pic1 and pic2) Everything else works fine but I’ve not been able to solve this small issue – any help would be appreciated.
The problem is for both “Category” and “Customer type”, but the code below is only for the “Category” field.
This is my code from the search_custom.js.
function addCatItem(){
var jsonstr = window.localStorage.getItem(‘data03’);
obj_data = JSON.parse(jsonstr);
var numofrec = obj_data.root.length;
var i = 0;
while(numofrec > [i]){
if(window.localStorage.getItem(‘cat’) == (obj_data.root[i].category.id))
{
newOpt = ‘<option value=”‘+(obj_data.root[i].category.id)+
‘” label=”‘+(obj_data.root[i].category.cat_name) +
‘” selected=””>’+(obj_data.root[i].category.cat_name)+'</option>’;
$(‘#m1-search-hidden-select-cat’).append(newOpt);
//alert(newOpt)
}
else
{
newOpt = ‘<option value=”‘+(obj_data.root[i].category.id)+
‘” label=”‘+(obj_data.root[i].category.cat_name) +
‘”>’+(obj_data.root[i].category.cat_name)+'</option>’;
$(‘#m1-search-hidden-select-cat’).append(newOpt);
}
i++;
}
}
Attachments:
You must be
logged in to view attached files.