martin47
Posts: 35
|
| Posted: 05/29/2008, 12:43 PM |
|
Greetings, Iīve benn playing around with this example: http://examples.codecharge.com/ExamplePack/PopUpList/PopUpList.php
So far I have a record with a popup where the user can pick a city from a popup list. I was wondering how can I change it so the popup returns two values instead of 1. I have the city name and the province on that grid and I would like to fill both fields on the record when the user clicks on the city name.
I supose the script included on the pop up should be changed, can somoeone help me how to retrieve the country value?
<script language="JavaScript" type="text/javascript">
function SetOpenerValue(currentObj)
{
var IE = (document.all) ? 1 : 0;
if(IE) {
var laVariable = currentObj.innerText;
} else {
var laVariable = currentObj.text;
}
window.opener.document.fichero_domicilios.LOCALIDAD.value = laVariable;
window.opener.focus();
window.close();
}
</script>
|
 |
 |
datadoit
|
| Posted: 05/29/2008, 1:16 PM |
|
Interesting question, and I think you're wanting something like an auto
form fill solution.
One way to do this would be to CONCAT the two fields you're wanting (if
they're both in the same table that is) for the bound column of your
lookup table. If that doesn't make sense lemme know and I'll toss over
an example of how to do that.
CONCAT with some character that's not likely to be in your data (such as
the pipe - |). Then, in the javascript before you assign the value to
the opener form field, split out the value into an array:
var ValuesArray = currentObj.text.split('|');
window.opener.document.fichero_domicilios.LOCALIDAD.value = ValuesArray[0];
window.opener.document.fichero_domicilios.COUNTRY.value = ValuesArray[1];
The above is untested (looks like it should work though), but gives you
an idea of using the javascript split() function.
Another way would be to use AJAX. Do your popup as normal, change the
opener value, then close the popup window. Then, in your calling form
field's onChange event write an AJAX function that will do the lookup
for the data you need for the rest of your form fields. The form fill
portion will occur without your screen having to refresh.
|
|
|
 |
martin47
Posts: 35
|
| Posted: 05/29/2008, 1:41 PM |
|
I wonder how to do that, the concatenated object. Because Im actually willing to pass 4 elements:
location name
location id
province name
province id
I wonder if it is possible to do this: on the grid, show the location name, and when clicked it passes all those values concatenated into the (currentObj) value?
I donīt really know if there is a way to do that, Iīm taking my first steps on CodeCharge!
|
 |
 |
martin47
Posts: 35
|
| Posted: 05/29/2008, 1:56 PM |
|
I wonder if what should be changed is the onclick event: SetOpenerValue(this);return false;
Making it some way that instead of sending "this", sends all the variables from that gridīs row concatenated?
Does it osund logic? Can be done?
|
 |
 |
datadoit
|
| Posted: 05/29/2008, 4:32 PM |
|
This worked for me:
In your popup window's grid and link, in the onClick event where you
specify the SetOpenerValue(this), instead of saying "this", put
something like...
SetOpenerValue('{field1}|{field2}|{field3}'); return false;
Those {field} tags are the display fields from your grid (links or
labels of your database values).
Then in the javascript:
function SetOpenerValue(Values)
{
var ArrayVals = Values.split('|');
window.opener.document.fichero_domicilios.LOCALIDAD.value = ArrayVals[0];
window.opener.document.fichero_domicilios.LOCALNAME.value = ArrayVals[1];
}
|
|
|
 |
martin47
Posts: 35
|
| Posted: 05/30/2008, 10:34 AM |
|
It does not work for me.
The strangest thing happens: I paste this to the link on the grid:
SetOpenerValue("{LOCALIDAD}|{PROVINCIA}"); return false;
When I publish it, the link object gets converted to a regular text field!!!
I use double quotes, single ones. The same thing happens!
Any idea?
|
 |
 |
martin47
Posts: 35
|
| Posted: 05/30/2008, 10:54 AM |
|
I found a solution, there is no need to split anything:
SetOpenerValue("{LOCALIDAD}", "{PROVINCIA}"); return false;
Then on the function:
function SetOpenerValue(LOCALIDAD,PROVINCIA)
You can pass as many vars as you want!
Thanks datadoit for helping me solve this puzzle.
|
 |
 |
|