Hello,
I am using DHTMLXform for a project I am working on. I want to populate a select box with data from a database using Json. Below is my code to construct the form, followed by the code in getContractJson. The select box appears but it is empty. I have echoed out “$items” and the data is there. Thanks for your help!
Cheers,
[code]formData = [{
type: “select”,
position: “label-left”,
label:“Company Name”,
name: “companyname”,
//connector: “getContractXML.php”,
labelWidth: 200,
inputWidth: 80
}, {
type: “calendar”,
dateFormat: “%d-%m-%Y”,
name: “start_date”,
label: “Start Date”,
readonly: true,
value: “25-02-2013”,
enableTime: true,
calendarPosition: “right”
},{
type: “input”,
name: “duration”,
label: “Estimated Lesson Duration (hours)”,
value: “1.5”,
position: “center”
}, {
type: “input”,
name: “perweek”,
label: “Estimated #lessons/week”,
value: “2”
}];
myForm = new dhtmlXForm(“myForm”, formData);
myForm.load("getContractJson.php", "json");[/code]
getContractJson.php :
[code]…
$rs=$conn->execute($query);
$curr=0;
$items = array();
if($rs)
while (!$rs->EOF){
$companyID = strval($rs[‘CompanyID’]);
$companyName = strval($rs[‘CompanyName’]);
$items[$curr] = array(
‘companyid’ => $companyID,
‘companyname’ => $companyName
);
$rs->MoveNext();
$curr=$curr+1;
}
json_encode($items);
//return json_encode($items);
?>
[/code]