Main PHP program calls a Javascript specifying a return field. Sub PHP program is called in Javascript which displays some records from database. User select one of the record and Javascript returns the selected value to the specified field in Main PHP program.
This will work if the record is selected from the first screen displayed. It seems remember which target field to be returned. In some cases, Sub PHP program may be called more than once, such is, changing record selection criteria, or there are too many records in a screen and needed to limit only a certain records per screen.
If the Sub PHP program is called more than once, and the record is selected in the subsequent call. The record is not set in the Main PHP program. It seems losing the target field to be returned. Is there any way to overcome this problem?
Attached is the source codes involved in two program:
Main PHP (sy1002.php) HTML (using Smarty Template)
First function ("browse") calls aa1100b.php program to display record information Second function ("setTargetField") trys to set returned selected values to fields specified When HTML field "usr_address_code" is clicked, javascript "browse" is called
sy1002.tpl
function browse(start_key_value,targetField,targetField1) {
var aryFieldValues = null;
var w = window.open('aa1100b.php?adrAddressCode='+start_key_value,'','width=610,height=700,scrollbars=1');
w.targetField = targetField;
w.targetField1 = targetField1;
w.focus();
return false;
}
function setTargetField(targetField,targetFieldValue) {
if (targetField) {
targetField.value = targetFieldValue;
}
}
<form name="ERPsy1002" method="POST" action="sy1002.php">
<td>
<input type = "text" name = "usr_address_code" value ="{$strusr_address_code|escape}"
style = "ime-mode:disabled" size = "10" maxlength = "10" />
hyperlink here ="#" onclick="return browse(document.ERPsy1002.usr_address_code.value,document.ERPsy1002.usr_address_code,document.ERPsy1002.saveadl_name_language)"
{$lblsearch}
</td>
Sub PHP (aa1100b.php) HTML (using Smarty Template) Sub PHP access database and display list of records When one of records is selected, javascript "setFieldValues" is called "setFieldValues" calls "setTargetField" in Main PHP returning selected record to specified field
aa1100b.tpl
function setFieldValues(stradr_address_code,stradl_name_language) {
if (opener && !opener.closed && opener.setTargetField) {
opener.setTargetField(targetField, stradr_address_code);
}
if (opener && !opener.closed && opener.setTargetField) {
opener.setTargetField(targetField1, stradl_name_language);
}
window.close();
opener.focus();
}
<form name="Browseaa1100b" method="POST" action="aa1100b.php">
<td width="180px" align="center">
hyperlink here ="#" onclick = "setFieldValues(paradr_address_code {$smarty.foreach.loopTPL.iteration-1}.value,paradl_name_language{$smarty.foreach.loopTPL.iteration-1}.value)"
{$database->get_adr_address_code()}
</td>
When aa1100b.php is executed more than once before selecting a record, it does not set a value to the specified field in Main PHP