Skip to content

Instantly share code, notes, and snippets.

@ttoz ttoz/zip_search.html
Created Apr 24, 2012

What would you like to do?
Google Transliterationによる郵便番号からの住所検索
<script type="text/javascript" src=""></script>
<input type="text" class="zip" name="zip1" value="">
<input type="text" class="zip" name="zip2" value="">
<input type="button" value="郵便番号検索" onclick="getAddress()">
<script type="text/javascript">
function getAddress() {
var zipcode = [];
$('').each(function(){ zipcode.push($(this).attr('value')) });
$.getJSON('|ja&text=' + zipcode.join("-") + '&jsonp=?', function(json){
var addr = json[0][1][0];
$('#pref option').each(function(){
var pref = $(this).attr('value');
if (addr.indexOf(pref) == 0) {
$(this).attr('selected', 'selected');
$('#address').attr('value', addr.substr(pref.length));
<br />
<select id="pref" name="pref">
<option value="北海道">北海道</option>
<option value="沖縄県">沖縄県</option>
<br />
<input type="text" id="address" name="address" value="">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.