Created
April 24, 2012 07:55
-
-
Save ttoz/2477659 to your computer and use it in GitHub Desktop.
Google Transliterationによる郵便番号からの住所検索
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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