郵便番号から住所の自動入力がしたいと考えておりますが、
コンソールには表示されるものがフォームには表示されました。
開発ツールで確認すると、Uncaught TypeError: Cannot set property 'onfocus' of nullという表示が出てしまっております。
どうすれば「住所」の箇所に郵便番号から自動で入力できますでしょうか。
何卒よろしくお願いします。
javascript
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4 <meta charset="UTF-8"> 5 <title>フォーム:GET</title> 6 <link> 7 <script src="//code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script> 8 <script src="//jpostal.googlecode.com/svn/trunk/jquery.jpostal.js" type="text/javascript"></script> 9 <script type='text/javascript' src='http://code.jquery.com/jquery-git2.js'></script> 10<script type="text/javascript" src="http://jpostal.googlecode.com/svn/trunk/jquery.jpostal.js"></script> 11 12 13 <script type="text/javascript"> 14 $(window).ready( function() { 15 $('#postcode1').jpostal({ 16 postcode : [ 17 '#postcode1', 18 '#postcode2' 19 ], 20 address : { 21 '#address1' : '%3', 22 '#address2' : '%4', 23 '#address3' : '%5' 24 } 25 }); 26}); 27 $(window).ready( function() { 28 $('#postcode1').jpostal({ 29 postcode : [ 30 '#postalcode', 31 32 ], 33 address : { 34 '#address' : '%3', 35 } 36 }); 37 }); 38 //<!-- 透かし文字をvalue属性で設定する --> 39<!-- 40 var textbox = document.getElementById( 'textbox' ); 41 42 // 入力フォーカスを得たときの処理 43 textbox.onfocus = function() 44 { 45 if( this.value == this.defaultValue ) 46 { 47 this.value = ''; 48 this.style.color = ''; 49 } 50 } 51 52 // 入力フォーカスを失ったときの処理 53 textbox.onblur = function() 54 { 55 if( this.value == '' ) 56 { 57 this.value = this.defaultValue; 58 this.style.color = 'gray'; 59 } 60 } 61 62 // 透かし文字をdefaultValueプロパティで保持する 63 textbox.defaultValue = textbox.value; 64 textbox.value = ''; 65 66 textbox.onblur(); 67//--> 68 myform.myarea.value="住所"; 69</script> 70</head> 71<body> 72 73<form name="myform" method="post" action="fputs.php"> 74<p>お名前:<input type="text" name="name" size="20"></p> 75<p>MAIL:<input type="text" name="mail" size="30"></p> 76<p>電話:<input type="text" name="tell" size="20"></p> 77 <p>郵便番号:<input id="postcode1" name="postcode1" maxlength="3">-<input id="postcode2" name="postcode2" maxlength="4"><br /></p> 78<p>住所:<input type="text" id="textbox" id="address" name="adress" size="20" name="myarea"></p> 79性別: 80<input type="radio" name="性別" value="男" /> 男 81<input type="radio" name="性別" value="女" /> 女 82<br> 83<br> 84<textarea name="iken" rows="4" cols="40"> 自由に意見を記述してください </textarea> 85 86<p><input type="submit" value="送信"></p> 87</form> 88 89</body> 90</html> 91 92```
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。