This topic is locked
[SOLVED]

  Get "Displayed value" not "record ID" for dropdown to fill other calculated values

1/17/2012 9:40:31 PM
PHPRunner General questions
M
mcappel author

Hi
I Have a ADD form with the following fields
Address (text field)

City (dropdown with lookup in table city with 'ID','cityName' fields showing cityName )

Province(dropdown with lookup in table province with 'ID','provinceName' fields showing ProvinceName)

Country (text field)

FullAddress (calculated value with AJAX as address+City+province+Country)
I am trying to calculate and fill the value of FullAddess with the following Javascript but I get the ID for files City and Province and I need the displayed Name. I mean CityNAme and ProvinceName

function OnPageLoad(pageid){
var ctrlAddress = Runner.getControl(pageid, 'Address');

var ctrlCity = Runner.getControl(pageid, 'City');

var ctrlProvince = Runner.getControl(pageid, 'Province');

var ctrlCountry = Runner.getControl(pageid, 'Country');
var ctrlFullAddress = Runner.getControl(pageid, 'FullAddress');

function func() {

var temp=ctrlCity.getDispElem() .val()

ctrlFullAddress.setValue(ctrlAddress.getValue()+', '+ctrlCity.getValue()+', '+ctrlProvince.getValue()+', '+ctrlCountry.getValue());

};

ctrlAddress.on('change', func);

ctrlCity.on('change', func);

ctrlProvince.on('change', func);

ctrlCountry.on('change', func);

}


Javascript functions ctrlCity.getValue() and ctrlProvince.getValue() are showing ID values instead of Displayed Values.
Is there any way I can get the Displayed Name with Javascript ???
Help !!!

Thanks

MAC

C
cgphp 1/18/2012
function func() {

var city = $(ctrlCity.getDispElem()+':selected').text();

var province = $(ctrlProvince.getDispElem()+':selected').text();

ctrlFullAddress.setValue(ctrlAddress.getValue()+', '+city+', '+province+', '+ctrlCountry.getValue());

};
M
mcappel author 1/18/2012


function func() {

var city = $(ctrlCity.getDispElem()+':selected').text();

var province = $(ctrlProvince.getDispElem()+':selected').text();

ctrlFullAddress.setValue(ctrlAddress.getValue()+', '+city+', '+province+', '+ctrlCountry.getValue());

};



Hi Cristian
Thanks for your help, I still have a problem the variables city and province are filled with the content of all selected dropdowns and not the city and province respectively .

For example if I have selected the following dropdowns city=Calgary, province=Alberta in the city dropdown I get the values CalgaryAlberta, I guess the ctrCity.getDispElem():selected returns the object for the whole page and not for the field it refers to. the same object/element is retrieve by the call to the function ctrProvince.getDispElement():selected

Any hint?
Thanks

MAC

C
cgphp 1/19/2012

Please, post the full code.

M
mcappel author 2/8/2012



Please, post the full code.



Here is the solution. If you have more than one dropdown field, the function getDispElem returns all the dropdown selected objects together, and is not only limited to the one getControl has assigned control, looks a bug on the code of phprunner. Note that i have to use index variable in order to choose the required fields for the calculated FullAddress
The final code that works is:

var ctrlAddress = Runner.getControl(pageid, 'Address');

var ctrlCity = Runner.getControl(pageid, 'City');

var ctrlProvince = Runner.getControl(pageid, 'Province');

var ctrlCountry = Runner.getControl(pageid, 'Country');
var ctrlFullAddress = Runner.getControl(pageid, 'FullAddress');
function func() {

var str=new Array();

$(ctrlCity.getDispElem()+':selected').each(function (index) {

str[index] = $(this).text() ;

});
ctrlFullAddress.setValue(ctrlAddress.getValue()+', '+str[2]+', '+str[1]+', '+ctrlCountry.getValue());
};

ctrlAddress.on('change', func);

ctrlCity.on('change', func);

ctrlProvince.on('change', func);

ctrlCountry.on('change', func);


Regards

Mauro