선택장애

radio box - 클릭시 input box 값 바꾸기 본문

자바스크립트

radio box - 클릭시 input box 값 바꾸기

yes or yes 2020. 9. 1. 10:27
반응형

1. 먼저 radio box, input box를 만들어줍니다.

<input type="radio" value="11"> test11

<input type="radio" value="22"> test22

<input type="radio" value="33"> test33

<input type="text" id="ch_txt">

 

2. Onclick 이벤트를 추가해줍니다.

<input type="radio" onclick="document.getElementById('ch_txt').value=this.value" value="11"> test11

<input type="radio" onclick="document.getElementById('ch_txt').value=this.value" value="22"> test22

<input type="radio" onclick="document.getElementById('ch_txt').value=this.value" value="33"> test33

<input type="text" id="ch_txt" value="초기값">

 

3. 기능은 되지만 box와 text의 높이가 안 맞다면

radio box에 style="vertical-align:-2px" 을 추가해줍니다.

반응형