Problem/front

form태그로 첨부파일 전송 form 제목 내용 입력 체크(빈값체크)

늉_늉 2020. 12. 22. 09:34

onsubmit="return reportSend(); 

 

 

폼 전송전에 작업 수행하게 하는 이벤트

 

 

전송 버튼을 클릭하면 reportSend() 함수를 호출하라 라는 뜻

 

 

reportSend()는 제목과 내용의 빈값을 체크하는 함수이다.

 

 

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
   <form action="popEmployeeReportSend" id ="popEmployeeReportSend" name="popEmployeeReportSend" method="post" enctype="multipart/form-data" onsubmit="return reportSend();">
            <div class="m_button"><button type="submit">직원소리 발송하기</button></div>
            <table>
                <tr>
                    <th>제목</th>
                    <td><input type="text" id ="reportTitle" name ="reportTitle"></td>
                </tr>
                <tr>
                    <th>내용</th>
                    <td><textarea id = "reportContents" name ="reportContents"> </textarea></td>
                </tr>
                <tr>
                    <th>첨부파일 </th>
                    <td><input type="file" name="attachFile" id="attachFile"></td>
                </tr>
    
    
            </table>
        </form>
 
    </div>
    <script>
        function reportSend() {
            console.log("resport Send");
            var reportTitle = $("#reportTitle").val().trim();
            var reportContents = $("#reportContents").val().trim();
 
            if (!reportTitle) {
                console.log(reportTitle);
                alert('제목이 입력되지 않았습니다.');
 
                return false;
            }
            if (!reportContents) {
                alert('내용이 입력되지 않았습니다.');
                return false;
            }
 
        }
 
        function close() {
            window.close();
        }
    </script>
cs

'Problem > front' 카테고리의 다른 글

jstl foreach 사용법  (0) 2020.12.24