This is a generic user guide to using our JavaScript. As standard the JavaScript class allows easy integration of RapidAddress and FlexiAddress into any HTML page. Feel free to contact us should you need any help with integration.
Code for the class can be downloaded from the downloads section.
If using the compressed version of the class, charset needs to be set to "ISO-8859-1", eg:
<script type="text/javascript" charset="ISO-8859-1" src="crafty_postcode.class.js"> </script>
To create and configure a JavaScript object:
<script>
var cp_obj = CraftyPostcodeCreate();
cp_obj.set("access_token", "xxxxx-xxxxx-xxxxx-xxxxx"); // your token here
cp_obj.set("option_1", "value_1");
...
cp_obj.set("option_n", "value_n");
</script>
If you want to use address lookup more than once on a page, you can create multiple objects. Each object can be used independently of the others :
var cp_obj_1 = CraftyPostcodeCreate(); .... var cp_obj_n = CraftyPostcodeCreate();
| Option Name | Description |
| access_token | your web service access token |
| result_elem_id | id of the element where the result drop down box, or notice/error messages will be placed |
| form | name of the form containing address fields, if set elem_* options are set to names of the form fields; if left blank elem_* options must be set to id's |
| elem_company | name or id of the input element, can be blank |
| elem_house_num | name or id of the input element, can be blank |
| elem_street1 | name or id of the input element, required, must be set |
| elem_street2 | name or id of the input element, can be blank |
| elem_street3 | name or id of the input element, can be blank |
| elem_town | name or id of the input element, required, must be set |
| elem_county | name or id of the input element, can be blank |
| elem_postcode | name or id of the input element, required, must be set; this is both an input and an output |
| traditional_county | which flavour of county info is shown 0 - postal county (default), 1 - traditional county name |
| busy_img_url | set the location of a busy image, default is 'crafty_postcode_busy.gif' - this is shown while we wait for the server response |
| max_width | set if you want to limit the width of the result box (in px), eg "450px" |
| max_lines | set the max number of text lines in the result box |
| hide_result | 1 - results box disappears once a result is clicked, 0 - it stays up (default) |
| org_uppercase | 0 - company name with leading upper case, 1- all in upper case (default) |
| town_uppercase | 0 - leading upper case, 1- all in upper case (default, recommended by Royal Mail) |
| county_uppercase | 0 - leading upper case (default), 1- all in upper case |
| addr_uppercase | 0 - rest of address lines with leading upper case (default), 1- all in upper case |
| delimiter | delimiter to use between parts of the address, eg ", " (default) |
| msg1 | msg to attach as title to busy image, default - 'Please wait while we find the address' |
| err_msg1 | error msg if postcode does not exist, default - 'This postcode could not be found, please try again or enter your address manually' |
| err_msg2 | error msg if postcode is not correctly formatted, default - 'This postcode is not valid, please try again or enter your address manually' |
| err_msg3 | error msg if there is network problem, default - 'Unable to connect to address lookup server, please enter your address manually.' |
| err_msg4 | error msg to cover any other problem, default - (err_num)+'An unexpected error occurred, please enter your address manually.' |
| res_autoselect | 1 - the first result will be auto-selected as soon as the result box is shown (default), 0 - it won't |
| res_select_on_change | 1 - results will be selected as the user scrolls through the box (default), 0 - user must explicitly click to select |
| first_res_line | option to add a dummy 1st line eg '----- please select your address ----', blank by default |
| debug_mode | set it to 1 to get more descriptive error messages in case of trouble, default is 0 |
| lookup_timeout | maximum time to spend waiting for lookup server response (in milliseconds), default 10000, i.e. 10 seconds. |
| on_result_ready | callback function name called when result is received from the lookup server |
| on_result_selected | callback function name called when the user clicks on a result |
| on_error | callback function called if there is an error |
| pre_populate_common_address_parts | 1 - every time the drop-down is shown all common parts of the address get placed on the form, default is 0 |
| lookup_url | set to use a data relay script, by default set to access the CraftyClicks web service directly |
| basic_address | 0 - Rapid/Flexi Address, 1 - Basic Address |
| single_res_autoselect | 1 - if only one result is found, we select it right away rather than show a one line drop down! |
| single_res_notice | if single_res_autoselect = 1, show this message if drop down in not shown |
There are two methods to tell the object where to find the address form fields:
<script>
cp_obj.set("form" , "XYZ");
cp_obj.set("elem_company" , "companyname");
cp_obj.set("elem_street1" , "address1");
//... etc ...
</script>
Add id="*_id" to every <input> field.
<script>
cp_obj.set("form", "");
cp_obj.set("elem_company" , "companyname_id");
cp_obj.set("elem_street1" , "address1_id");
//... etc ...
</script>
Not all address fields need to be set, the minimum set would be:
cp_obj.set("elem_company" , "");
cp_obj.set("elem_street1" , "address1");
cp_obj.set("elem_street2" , "");
cp_obj.set("elem_street3" , "");
cp_obj.set("elem_town" , "town");
cp_obj.set("elem_county" , "");
cp_obj.set("elem_postcode" , "postcode");
cp_obj.set("elem_house_num", "");
If things don't work right away, set the object into debug mode and see if the error messages give any clues:
cp_obj.set("debug_mode", "1");
If you still have no luck - email any error codes/messages to us. We will be happy to help.