I am trying to apply the initial value for a Select Object that is not associated to the form's table. I can manage to retrieve and apply the value, but I guess its happening too late.
I have a Select Object (t1_id) that is part of a Dependent Dropdown Entry / Edit form to filter the Options List in the consequent Select Object (t2_id) on the same form (frmT3). t2_id is actually read/written in the form's table (tblT3), where as t1_id is recorded on a different table (tblT2).
So, to get an initial value into t1_id, I have to run a query before the form opens.
frmT3 > t1_id > Select (SQL):
Code: Select all
SELECT
tblT1.tblT1_id,
CONCAT(t1_name,'|',t2_label)
FROM
tblT1
Code: Select all
SELECT
tblT2.tblT2_id,
CONCAT(tblT2.t2_name,'|',tblT2.t3_label')
FROM
tblT2
WHERE
tblT2.t1_id = '#t1_id#'
Code: Select all
$s = "SELECT tblT1_id FROM tblT1 JOIN tblT2 ON t1_id = tbT1_id JOIN tblT3 ON t2_id = tblT2_id WHERE tblT3_id = '#RECORD_ID#'";
$t = nuRunQuery($s, array('#LOOKUP_RECORD_ID#'));
if (db_num_rows($t) == 1) {
$r = db_fetch_object($t);
$j = "nuSetValue('t1_id','$r->tblT1_id');nuRefreshSelectObject('t2_id');";
nuAddJavascript($j);
}
I have tried nuSetFormValue('t1_id','$r->tblT1_id); but unfortunately it does no work, but I guess it is meant for lookups only.
My guess is that nuAddJavascript is being applied too late, and that I need to apply the initial or selected="selected" from PHP?
Any help or advise would be greatly appreciated.