반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 백준
- crawling
- Intellij
- 비전공자
- springboot
- AWS
- 정보처리기사
- dataframe
- BeautifulSoup
- javascript
- 정처기
- 웹앱
- APPEND
- 자바스크립트
- sklearn
- lombok
- Req
- pandas
- SOUP
- regressor
- 크롤링
- ensemble
- pds
- list
- 자바
- java
- 정보처리기사필기
- BS
- request
- 머신러닝
Archives
- Today
- Total
No sweet without sweat
[웹앱 맨땅에 헤딩일기] - JSP 콤보박스 초기화 (.reset()) 본문
728x90
반응형
신청 후에 form을 초기화 하는 방법.
보통 콤보박스는 select으로 구성되어 있죠.
1. 콤보박스 하나씩 첫번째 옵션으로 처리하는 방법
<form id="myForm">
<!-- 폼 안에 있는 요소들 -->
<input type="text" id="nameInput" name="name" value="기본값">
<input type="checkbox" id="checkboxInput" name="checkbox" checked>
<select id="mySelect" name="mySelect">
<option value="option1">고기</option>
<option value="option2">생선</option>
</select>
<!-- 초기화 버튼 -->
<button type="button" onclick="resetForm()">폼 초기화</button>
</form>
<script>
function resetForm() {
// 각 요소의 값을 초기값으로 변경합니다.
document.getElementById("nameInput").value = "기본값";
document.getElementById("checkboxInput").checked = true;
document.getElementById("mySelect").selectedIndex = 0; // 첫 번째 옵션을 선택하도록 설정
}
</script>
2. form안에 있는 것을 한번에 초기
<form id="myForm">
<!-- 폼 안에 있는 요소들 -->
<input type="text" name="name" value="기본값">
<input type="checkbox" name="checkbox" checked>
<select name="mySelect">
<option value="option1">옵션 1</option>
<option value="option2">옵션 2</option>
</select>
<!-- 초기화 버튼 -->
<button type="button" onclick="resetForm()">폼 초기화</button>
</form>
<script>
function resetForm() {
// 폼을 초기화합니다.
document.getElementById("myForm").reset();
}
</script>
하나씩 하나씩 차근차근 해보자고요~~
728x90
반응형
Comments