본문 바로가기
jquery

Select 박스 선택값 input에 넣기 (ex. email 주소선택)

by 바나냥 2020. 4. 6.
    $("select[name=sel_email]").on("change", function(){
        var $addr = $(this).closest(".form").find("input[name=email_addr]");
        if ($(this).val() == "etc") {
            $addr.val('');
            $addr.prop("readonly",false);

        } else {
            $addr.val($(this).val());
            $addr.prop("readonly",true);
        }
    });

<div class="form">
    <span class="input w1 mailId"><input type="text" name="email_id" class="required" caption="이메일" maxlength="80" value=""></span>
    <span class="spaceTx">@</span>
    <span class="input w2 mailAddress"><input type="text" name="email_addr" class="required" caption="이메일" maxlength="50" value=""></span>
    <span class="select w1">
       <select name="sel_email">
           <option value="etc">직접입력</option>
           <option value="naver.com">naver.com</option>
           <option value="hanmail.net">hanmail.net</option>
           <option value="gmail.com">gmail.com</option>
           <option value="yahoo.com">yahoo.com</option>
           <option value="hotmail.com">hotmail.com</option>
           <option value="korea.com">korea.com</option>
           <option value="nate.com">nate.com</option>
       </select> 
    </span>
</div>

댓글