|
Hi Marcelo, I'm a bit of a novice, but this is exactly what I'm trying to do, and can't seem to make it work.. I wish you would have posted your working scripts because I didn't know what to do with the extra variable.. Here's what I've done, can you see my error(s)? I have a Master table 'Foreman's Daily Report' with a field 'Project'. I have a Details Table called 'Onsite Equipment' with a field 'Model' and I have another table 'Equipment' with fields 'Model' and 'CurrentLocation' I want the Lookup Wizard on 'Onsite Equipment' to only show 'Model' WHERE 'Project' (Master Table) = 'CurrentLocation'. So I put this in Master Table Add page, JavaScript OnLoad event:
//Lets make the LinkProductID field in master record trigger a dependent lookup in the child based on the selected product
var LinkProductID = Runner.getControl(pageid, 'Project'); //The window var is used by the details table to adjust the dependent dropdowns accordingly in JS onload events
LinkProductID.on('change',function(){
window.productID = this.getValue();
//console.log(window.productID); //debug
});
I put this in 'Onsite Equipment' Add page, JavaScript OnLoad event:
var ctrlModel = Runner.getControl(pageid, 'Model');
var func = function(e){
$.post("mylookup.php", {
'category' : window.productID },
function(data) {
setTimeout(function(){
var sel = $("#value_Model_1");
sel.empty();
for (var i=0; i<data.length; i++) {
sel.append('<option value="' + data[i].id + '">' + data[i].desc + '</option>');
}
},1000);//end setTimeout (set for 1 sec)
}, "json");
}; ctrlModel.on('keyup', func);
ctrlModel.on('change', func);
And I put this in mylookup.php file in output directory:
<?php include("include/dbcommon.php"); $result = array();
$make = db_addslashes(trim(postvalue('category')));
$sql = "SELECT * FROM Equipment WHERE currentLocation = '$make'";
$rs = CustomQuery($sql); while ($data = db_fetch_array($rs)) {
$result[] = array(
'id' => $data['Model'],
'desc' => $data['Model'],
);
}
echo json_encode($result);
?>
Incidentally, I couldn't find mylookup.php on the server, even after a full build/upload all files, so I manually uploaded it to the root directory on the server. Not really sure where the file is supposed to be.. Here is the console error that I'm getting: SCRIPT438: Object doesn't support property or method 'on' Here is the Debugger code:
Runner.pages.PageSettings.addPageEvent('Onsite Equipment',Runner.pages.constants.PAGE_ADD,"afterPageReady",function(pageObj,proxy,pageid,inlineRow,inlineObject){var ctrlModel=Runner.getControl(pageid,'model');var func=function(e){$.post("mylookup.php",{'category':window.productID},function(data){var sel=$("#value_Model_1");sel.empty();for(var i=0;i<data.length;i++){sel.append('<option value="'+data[i].id+'">'+data[i].desc+'</option>');}},"json");};ctrlModel.on('keyup',func);ctrlModel.on('change',func);});
Any help appreciated, Thanks!
|