Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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