EasyUI Forum
May 07, 2024, 04:37:05 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: ComboBox changes using select  (Read 4929 times)
karmac
Newbie
*
Posts: 1


View Profile
« on: November 26, 2013, 03:26:20 AM »

Hi,

I am trying to figure out how to update/append  the contents/options of easyui-combobox using javascript after fetching json data from server.

my script inside the .html

var xmlhttp = getRequestObject();
            xmlhttp.onreadystatechange = function()
            {
                 if ((xmlhttp.readyState === 4) && (xmlhttp.status === 200)) {
                    try {
                        var xmlDocument = xmlhttp.responseText;
                        var dpanel = document.getElementById("reportdate");
                        if(xmlDocument !== null) {
                            var valJS = JSON.parse(xmlDocument.toString());
                            var output = "";
                            $.each(valJS, function(key, obj) {
                                output += '<option value="'+ obj +'">'+ obj +'</option>';
                                });
                            dpanel.innerHTML=output;
                        }
                    }
                    catch (err) {
                        alert("error=" + err.message);
                    }
                }
            };

the html code is as follows

 <div id="datepanel">
           
            <select  name="reportdate" id="reportdate" style="width:200px;" class="easyui-combobox">
            </select>

 </div>

With the above code once the page is loaded, i am able to see <options> inside the select updated, but the same is not reflected in the combobox[ie the combo is empty].
On the other hand, if i remove the class="easyui-combobox", the the options are visible on the page.

I dont know what i am doing wrong. Any help would be greatly appreciated.


Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: November 26, 2013, 08:19:08 AM »

Calling 'loadData' method is the simplest way to update combobox's data.
Code:
var data = ...  // get data
$('#reportdata').combobox('loadData', data);
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!