Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app">
    <form>
        <table>
            <tbody>
                <tr>
                    <th>郵便番号</th>
                    <td>
                        <input id="input" class="zipcode" type="text" name="zipcode" value="" placeholder="例)8120012">
                        <button id="search" type="button">住所検索</button>
                        <p id="error"></p>
                    </td>
                </tr>

                <tr>
                    <th>都道府県</th>
                    <td><input id="address1" type="text" name="address1" value=""></td>
                </tr>

                <tr>
                    <th>市区町村</th>
                    <td><input id="address2" type="text" name="address2" value=""></td>
                </tr>

                <tr>
                    <th>町域</th>
                    <td><input id="address3" type="text" name="address3" value=""></td>
                </tr>
            </tbody>
        </table>
    </form>
</div>
              
            
!

CSS

              
                #app {
    width: 96%;
    max-width: 500px;
    margin: 40px auto;
    padding: 20px;
    padding: 28px;
    line-height: 1.5;
    border: 1px solid #ffffff;
    border-radius: 5px;
    background-color: transparent;
    box-shadow: 2px 2px 5px 0px rgba(200, 200, 200, 1);
    font-family: "Times New Roman";
}

#error {
    margin: 5px 0 0 0;
    color: #ff0000;
    font-size: .84rem;
    font-weight: bold;
}

table {
    display: table;
    width: 100%;
    border-collapse: collapse;
    
    tbody {
        tr {
            th {
                width: 80px;
                padding: 20px 10px;
                text-align: left;
                border-bottom: 2px solid #384878;
            }
            
            td {
                width: calc(100% - 80px);
                padding: 20px 10px;
                border-bottom: 2px solid #cccccc;
                
                input {
                    padding: 5px;
                    border: 0;
                    border: 1px solid #cccccc;
                }
                
                button {
                    padding: 3px 10px;
                    color: #ffffff;
                    background-color: #00c2bc;
                    border: 0;
                    box-shadow: none;
                    cursor: pointer;
                }
                
                .zipcode {
                    width: 75px;
                }
            }
        }
    }
}
              
            
!

JS

              
                let search = document.getElementById('search');
search.addEventListener('click', ()=>{
    
    let api = 'https://zipcloud.ibsnet.co.jp/api/search?zipcode=';
    let error = document.getElementById('error');
    let input = document.getElementById('input');
    let address1 = document.getElementById('address1');
    let address2 = document.getElementById('address2');
    let address3 = document.getElementById('address3');
    let param = input.value.replace("-",""); //入力された郵便番号から「-」を削除
    let url = api + param;
    
    fetchJsonp(url, {
        timeout: 10000, //タイムアウト時間
    })
    .then((response)=>{
        error.textContent = ''; //HTML側のエラーメッセージ初期化
        return response.json();  
    })
    .then((data)=>{
        if(data.status === 400){ //エラー時
            error.textContent = data.message;
        }else if(data.results === null){
            error.textContent = '郵便番号から住所が見つかりませんでした。';
        } else {
            address1.value = data.results[0].address1;
            address2.value = data.results[0].address2;
            address3.value = data.results[0].address3;
        }
    })
    .catch((ex)=>{ //例外処理
        console.log(ex);
    });
}, false);

              
            
!
999px

Console