Postcode Lookup on two forms - Crafty Clicks
UK postcode lookup on two forms, using input element IDs to config the Crafty Clicks JS,
HTML
<script src="https://cc-cdn.com/legacy/scripts/v4.9.2/crafty_clicks.class.min.js"></script>
<span style="font-size:small">Use the free postcodes AA11AA, AA11AB, AA11AD or AA11AE.<br/>To try real data, you will need to paste an access token into this code!</span><br/>
<br/>
<form method="post" name="bill_address">
Billing Postcode:<br/>
<input type="text" name="postcode" id="postcode_1" value="AA11AA"/>
<button type="button" onclick="cp_obj_1.doLookup()">Find Address</button><br/>
<span id="crafty_postcode_result_display_1"> </span><br/>
Billing Company:<br/>
<input type="text" name="companyname" id="companyname_1"/><br/>
Billing Address:<br/>
<input type="text" name="address1" id="address1_1"/><br/>
<input type="text" name="address2" id="address2_1"/><br/>
<input type="text" name="address3" id="address3_1"/><br/>
Billing Town:<br/>
<input type="text" name="town" id="town_1"/><br/>
</form>
<br/><br/>
<form method="post" name="ship_address">
Shipping Postcode:<br/>
<input type="text" name="postcode" id="postcode_2" value="AA11AB"/>
<button type="button" onclick="cp_obj_2.doLookup()">Find Address</button><br/>
<span id="crafty_postcode_result_display_2"> </span><br/>
Shipping Company:<br/>
<input type="text" name="companyname" id="companyname_2"/><br/>
Shipping Address:<br/>
<input type="text" name="address1" id="address1_2"/><br/>
<input type="text" name="address2" id="address2_2"/><br/>
<input type="text" name="address3" id="address3_2"/><br/>
Shipping Town:<br/>
<input type="text" name="town" id="town_2"/><br/>
</form>
JavaScript
var cp_obj_1 = CraftyPostcodeCreate();
cp_obj_1.set("access_token", "xxxxx-xxxxx-xxxxx-xxxxx"); // your token here
cp_obj_1.set("result_elem_id", "crafty_postcode_result_display_1");
cp_obj_1.set("form", ""); // left blank, we will use element id's
cp_obj_1.set("elem_company" , "companyname_1");
cp_obj_1.set("elem_street1" , "address1_1");
cp_obj_1.set("elem_street2" , "address2_1");
cp_obj_1.set("elem_street3" , "address3_1");
cp_obj_1.set("elem_town" , "town_1");
cp_obj_1.set("elem_postcode" , "postcode_1");
var cp_obj_2 = CraftyPostcodeCreate();
cp_obj_2.set("access_token", "xxxxx-xxxxx-xxxxx-xxxxx"); // your token here
cp_obj_2.set("result_elem_id", "crafty_postcode_result_display_2");
cp_obj_2.set("form", ""); // left blank, we will use element id's
cp_obj_2.set("elem_company" , "companyname_2");
cp_obj_2.set("elem_street1" , "address1_2");
cp_obj_2.set("elem_street2" , "address2_2");
cp_obj_2.set("elem_street3" , "address3_2");
cp_obj_2.set("elem_town" , "town_2");
cp_obj_2.set("elem_postcode" , "postcode_2");