Skip to content

Instantly share code, notes, and snippets.

@ttoz
Created April 24, 2012 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttoz/2477659 to your computer and use it in GitHub Desktop.
Save ttoz/2477659 to your computer and use it in GitHub Desktop.
Google Transliterationによる郵便番号からの住所検索
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></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 = [];
$('input.zip').each(function(){ zipcode.push($(this).attr('value')) });
$.getJSON('http://www.google.com/transliterate?langpair=ja-Hira|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));
}
});
})
}
</script>
<br />
<select id="pref" name="pref">
<option value="北海道">北海道</option>
...
<option value="沖縄県">沖縄県</option>
</select>
<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