WORK/JQUERY

동일한 input text , select box 에 값 넣기

im 수캥이 2019. 3. 11. 19:17

지난번에 동일한 input name 값 가지고 오는걸 알아봤었다.


https://choija.tistory.com/63?category=811723


이번에는 동일한 input 값에 데이터를 set 하는 방법에 대해 알아보자.



<script>
    function fnDataSet(dataSet){
        // 데이터 리스트 를 불러온다.
        $.each(dataSet,function(key,json){
            $("input[name='EMAIL']").each(function (idx) {
                // input 값에 데이터 set
                $("input[name='EMAIL']").eq(idx).val(json.EMAIL); 
                // select box에 데이터 set
                $("select[name='SEL_CODE']").eq(idx).val(json.COUNTRY_CODE);
            });
                
        });
    }
</script>
<body>
 
    <tr>
        <td><input type="text" name="EMAIL" id="EMAIL" value="" ></td>
        <td><input type="text" name="EMAIL" id="EMAIL" value="" ></td>
        <td><input type="text" name="EMAIL" id="EMAIL" value="" ></td>
        <td>
            <select name="SEL_CODE" id="SEL_CODE">
                <option value="01">첫번째</option>
                <option value="02">두번째</option>
                <option value="03">세번째</option>
            </select>
        </td>
        <td>
            <select name="SEL_CODE" id="SEL_CODE">
                <option value="01">첫번째</option>
                <option value="02">두번째</option>
                <option value="03">세번째</option>
            </select>
        </td>
        <td>
            <select name="SEL_CODE" id="SEL_CODE">
                <option value="01">첫번째</option>
                <option value="02">두번째</option>
                <option value="03">세번째</option>
            </select>
        </td>
    </tr>
 
</body>
 
cs