<link rel="stylesheet" href="https://cloud.hopewiser.com/jsclient2/hpw-jsclient2.css" />
Before the </body> closing tag of your web page, add these lines…
<script src="https://cloud.hopewiser.com/jsclient2/jquery.min.js"></script>
<script src="https://cloud.hopewiser.com/jsclient2/bootstrap.min.js"></script>
<script src="https://cloud.hopewiser.com/jsclient2/json2.min.js"></script>
<script src="https://cloud.hopewiser.com/jsclient2/hpw-jsclient2.min.js"></script>
Replace ‘https://cloud.hopewiser.com/jsclient2’ with the relative path of the folder if you chose to install these files on your own web server in place of using the Hopewiser hosted resources. Details of how to obtain local JavaScript components required can be located in the Customisation section “How do I install AutoComplete JavaScript Client service files locally?”.
If your web site is already using jQuery, Bootstrap or json2, you may be able to omit the applicable lines or reference your existing installation as necessary.
Add a button with the following attributes to your web page:
<button type="button" data-toggle="modal" data-target="#hpwModal" data-backdrop="static" onclick="btnFindAddress_onclick()">Find Address</button>
In the <head> of your web page, add a script to handle the button’s onclick event. In the button’s onclick handler, call the HPW.FindAddress() function:
<script>
function btnFindAddress_onclick() {
HPW.FindAddress({...});
}
</script>
The HPW.FindAddress() function takes a JavaScript object containing:
- Your authorisation code
- The dataset to look up against
- The HTML ID of your input field
- An object containing the HTML IDs of your output fields
- Optionally, parameters to indicate if you want to include the County or any Organisation Name within the matched address, and whether you want the town in upper or lower case.
| Optional Parameter |
Description |
| IncludeCounty |
Select when the county should be included within the formatted address label. Allowed values are Always, Never or AsRequired (the default).
The value AsRequired will only include the county when appropriate, for example when it meets PTT guidelines or when it is required to disambiguate UK town names. |
| ReserveOrganisationLine |
Select the position of the organisation within the formatted label. Allowed values are AsRequired (the default), Always or Never.
The value AsRequired includes the organisation within the address label following standard formatting rules.
The value Always reserves the first line of the formatted address label for the organisation and forces it to be output on a separate line. If there is no organisation then the first line will be empty.
The value Never removes the organisation from the formatted address label. |
| TownFormat |
Select the required town format. Allowed values are Uppercase (the default) or Lowercase. |
If your web page has separate address fields
Specify their HTML IDs in the output object, e.g.
function btnFindAddress_onclick() {
HPW.FindAddress({
auth: "yourAuthCode", // required
dataset: "uk-rm-paf-mr", // required
input: "txtInput", // required
output: {
line1: "txtLine1", // required
line2: "txtLine2", // required
line3: "txtLine3", // optional
line4: "", // optional
town: "txtTown", // required
county: "txtCounty", // optional
postcode: "txtPostcode", // required
country: "txtCountry" // optional
},
IncludeCounty: "AsRequired", // optional (default = "AsRequired")
ReserveOrganisationLine: "AsRequired", // optional (default = "AsRequired")
TownFormat: "Uppercase" // optional (default = "Uppercase")
});
}
If your web page has a single multi-line address field
Specify its HTML ID against each address line you want to be returned, e.g.
function btnFindAddress_onclick() {
HPW.FindAddress({
auth: "yourAuthCode", // required
dataset: "uk-rm-paf-mr", // required
input: "txtInput", // required
output: {
line1: "txtAddress", // required
line2: "txtAddress", // required
line3: "txtAddress", // optional
line4: "", // optional
town: "txtAddress", // required
county: "txtAddress", // optional
postcode: "txtAddress", // required
country: "txtAddress" // optional
},
IncludeCounty: "AsRequired", // optional (default = "AsRequired")
ReserveOrganisationLine: "AsRequired", // optional (default = "AsRequired")
TownFormat: "Uppercase" // optional (default = "Uppercase")
});
}
If your web page has a mixture of multi-line and individual address fields
For each address line you want, specify the HTML ID of the field you want it returned to, e.g.
function btnFindAddress_onclick() {
HPW.FindAddress({
auth: "yourAuthCode", // required
dataset: "uk-rm-paf-mr", // required
input: "txtInput", // required
output: {
line1: "txtStreet", // required
line2: "txtStreet", // required
line3: "txtStreet", // optional
line4: "", // optional
town: "txtTown", // required
county: "txtCounty", // optional
postcode: "txtPostcode", // required
country: "txtCountry" // optional
},
IncludeCounty: "AsRequired", // optional (default = "AsRequired")
ReserveOrganisationLine: "AsRequired", // optional (default = "AsRequired")
TownFormat: "Uppercase" // optional (default = "Uppercase")
});
}
Replace yourAuthCode with your authorisation code and the example HTML IDs with your actual HTML IDs. If you do not specify an ID for line3 or line4, the returned address will be formatted to fit the available lines. The county ID should be used in conjunction with the IncludeCounty parameter, and must be specified when the county is required. If you do not specify an ID for country, then it will be omitted. The input field does not have to be a separate field; it can be one of the output fields, in which case it would most likely be the postcode field.
How do I lookup an address?
Type a postcode into your input field then click the Find Address button. Select an address from the list of possible matches then click the Select button. Repeat if necessary until you have the address you want.
How do I troubleshoot my installation?
NOTE: your web page must be served up via a web server, using the http:// or https:// protocol. The JavaScript Client will not work if you open your web page directly from the file system, using the file:// protocol.
You can set the Debug flag found in the autocomplete-javascript-client sample page to true. This will display a message box to the user if there are any missing or invalid fields
IE Compatibility Modes
The JavaScript Client uses Bootstrap, which is not supported in the old Internet Explorer compatibility modes. To be sure you’re using the latest rendering mode for IE, consider including the appropriate <meta> tag in your page:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Confirm the document mode by opening the debugging tools: press F12 and check the “Document Mode”.