If you add this method to your page's controller:
global with sharing class MyController {
@RemoteAction
global static String findLocation(String city, String country) {
// Execute Apex logic here using only "city" and "country"
return ...
}
}
then Visualforce will generate a JavaScript function (named MyController.findLocation
) that you can just call e.g. from your other findLocation
function:
function findLocation() {
var city;
var country;
...
MyController.findLocation(city, country, new function(result, event) {
// Set the inputField value to the result in here
});
...
}
This is the JavaScript Remoting for Apex Controllers approach mentioned in Seb__Wagner's answer. It has the (performance) advantage that no view state is transmitted: you just pass the values needed and it performs its action and returns the result (via a callback function).