YuubinBango is a similar and newer library. It uses classes to setup the form making it easier and cleaner to implement. The downside of this library is that it cannot use your preferred event and it only use onkeyup. To implement, read Auto fill Japanese address from zip code with YubinBango.
On the other hand, please use AjaxZip3 and continue reading below if you want the address to be autofilled only after a button click or any other event than onkeyup.
<script src="https://ajaxzip3.github.io/ajaxzip3.js" charset="UTF-8"></script>
AjaxZip3 supports separated or combined address fields. For the example below, 2 zip code fields and 3 address fields are used.
// Zip entry field is divided into two, namely zip and zip2.
<input type="text" name="zip1" size="4" maxlength="3">-<input type="text" name="zip2" size="5" maxlength="4">
// Prefecture
<input type="text" name="pref" size="40">
// City or Municipality
<input type="text" name="address1" size="40">
// The rest of the address such as street and town
<input type="text" name="address2" size="40">
<input type="text" name="zip2" size="5" maxlength="4"
onKeyUp="AjaxZip3.zip2addr('zip1','zip2','pref','address1','address2');">
The function above accepts 6 parameter values total and a minimum of 3.
AjaxZip3.zip2addr('zip1','zip2','prefecture','city','town','remaining_address');
The first parameter, zip1 is the first 3 numbers of a zip code while the second parameter, zip2 is the 4 remaining numbers.
From the third parameter is where the address startsーthe third is prefecture, the fourth is city, the fifth is town, and the last parameter is all the remaining address.
The last parameter is unnecessary as most of the address generated from the zip code calculation does not have a return value for it. It is safe to omit the last parameter, and if it exist, it will just combine with the 5th value.
By editing the function's parameter, the values can be customized and combined together.
The zip code can be combined to one value by setting the 2nd parameter to blank, and the address starting from third parameter can be combined to one field by entering the same field name on the 3rd and 4th parameter.
AjaxZip3.zip2addr('zip','','address','address');
The code above will only need one field for zip code, and one field for address.
<input type="text" name="zip" size="10" maxlength="8" onKeyUp="AjaxZip3.zip2addr('zip','','address','address');">
<input type="text" name="address" size="40">