JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Web Design 版  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 多個Form的submit問題
redhobor





發文: 20
積分: 0
於 2005-04-01 00:45 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page language="java" import="csproject.MarkManage, csproject.StudentManage, csproject.ModuleManage, java.sql.*, java.lang.*, java.lang.String, java.sql.ResultSet, javax.servlet.*"%>
<jsp:useBean id="rstStruct" class="csproject.ResultStructBean" scope="request">
<jsp:setProperty name="rstStruct" property="*"/>
</jsp:useBean>
<jsp:useBean id="student" class="csproject.StudentBean" scope="request">
<jsp:setProperty name="student" property="*"/>
</jsp:useBean>
<jsp:useBean id="rstExam" class="csproject.ResultExmBean" scope="request">
<jsp:setProperty name="rstExam" property="*"/>
</jsp:useBean>
<html>
<%
  String mdl_id = request.getParameter("mdl_id");
  String mdl_name = (String) request.getParameter("mdl_name");
  String std_id = "";
  String std_surname = "";
  String std_forename = "";
  StudentManage studentManage = new StudentManage();
  MarkManage markManage = new MarkManage();
  rstStruct = markManage.getModuleStruct(mdl_id);
  int countexam = rstStruct.countExam();
  rstExam = null;
  String rst_exmid = "";
  double rst_exmfirst = -1;
  boolean rst_exmhasresit = false;
  double rst_exmresit = -1;
  double rst_exmresult = -1;
%>
</script><style type="text/css">
  <!--
    .style5 {font-size: 10px}
    .style8 {font-size: 12px}
  -->
</style>
<table width="100%" border="0">
  <tr>
    <td height="69" colspan="3">
      <center>
      <form action="">
        <h2><%=mdl_id + " " + mdl_name%>        </h2>
        <table width="100%" border="0">
          <tr bgcolor="#CCCCCC">
            <td width="15%">Student ID</td>
            <td width="15%">Student Name</td>
            <td width="50%">Exam Results</td>
            <td width="10%">Confirm</td>
            <td width="10%">Reset</td>
          </tr>
          <tr>
          <%
            ResultSet rs_student = (ResultSet) studentManage.getAllStudents();
            //Check if any student exists
            //If there has no student information stored in database
            if (rs_student.wasNull()) {
              out.print("<tr>No Information!</tr>");
            }
            //If there has student informaiton stored in database, then displays exam information for each student.
            else {
              while (rs_student.next()) {
                out.print("<tr>");
                out.print("<form name=\"frmMark\" method=\"post\" action=\"inputexamservlet\">");
                std_id = rs_student.getString("std_id");
                std_surname = rs_student.getString("std_surname");
                std_forename = rs_student.getString("std_forename");
                out.print("<td>" + std_id + "</td>");
                out.print("<td>" + std_forename + " " + std_surname + "</td>");
                out.print("<input type=\"hidden\" name=\"mdl_id\" value=\"" + mdl_id + "\">");
                out.print("<input type=\"hidden\" name=\"std_id\" value=\"" + std_id + "\">");
                out.print("<input type=\"hidden\" name=\"std_name\" value=\"" + std_forename + " " + std_surname + "\">");
                out.print("<input type=\"hidden\" name=\"countexam\" value=\"" + countexam + "\">");
                out.print("<td>");
                out.print("<table>");
                out.print("<tr bgcolor=\"#CCCCCC\">");
                out.print("<td width=\"20%\">Exam ID</td>");
                out.print("<td width=\"20%\">First Result</td>");
                out.print("<td width=\"20%\">Has Resit?</td>");
                out.print("<td width=\"20%\">Resit Result</td>");
                out.print("<td width=\"20%\">Final Result</td>");
                out.print("</tr>");
                //Display every exam
                for (int i = 1; i <= countexam; i++) {
                  rst_exmid = Integer.toString(i);
                  out.print("<tr>");
                  out.print("<td>" + rst_exmid + "</td>");
                  out.print("<input type=\"hidden\" name=\"rst_exmid\" value=\"" + rst_exmid + "\">");
                  rstExam = markManage.getResultExm(mdl_id, std_id, rst_exmid);
                  //If this student has had results of exams
                  if (rstExam != null) {
                    rst_exmfirst = rstExam.getRst_exmfirst();
                    rst_exmhasresit = rstExam.getRst_exmhasresit();
                    rst_exmresit = rstExam.getRst_exmresit();
                    rst_exmresult = rstExam.getRst_exmresult();
                    if (rst_exmfirst != -1) {
                      out.print("<td><input type=\"text\" name=\"rst_exmfirst\" size=\"5\" value=\"" + rst_exmfirst + "\"></td>");
                    }
                    else {
                      out.print("<td><input type=\"text\" name=\"rst_exmfirst\" size=\"5\" value=\"NE\"></td>");
                    }
                    out.print("<td><select name=\"rst_exmhasresit\" size=\"1\">");
                    if (rst_exmhasresit) {
                      out.print("<option selected value=\"true\">Yes</option>");
                      out.print("<option value=\"false\">No</option>");
                    }
                    else {
                      out.print("<option value=\"true\">Yes</option>");
                      out.print("<option selected value=\"false\">No</option>");
                    }
                    out.print("</select></td>");
                    if (rst_exmresit != -1) {
                      out.print("<td><input type=\"text\" name=\"rst_exmresit\" size=\"5\" value=\"" + rst_exmresit + "\"></td>");
                    }
                    else {
                      out.print("<td><input type=\"text\" name=\"rst_exmresit\" size=\"5\" value=\"NE\"></td>");
                    }
                    if (rst_exmresult != -1) {
                      out.print("<td><input type=\"text\" name=\"rst_exmresult\" size=\"5\" value=\"" + rst_exmresult + "\"></td>");
                    }
                    else {
                      out.print("<td><input type=\"text\" name=\"rst_exmresult\" size=\"5\" value=\"NE\"></td>");
                    }
                  }
                  //If this student has no results of exams
                  else {
                    out.print("<td><input type=\"text\" name=\"rst_exmfirst\" size=\"5\" value=\"NE\"></td>");
                    out.print("<td><select name=\"rst_exmhasresit\" size=\"1\">");
                    out.print("<option value=\"true\">Yes</option>");
                    out.print("<option selected value=\"false\">No</option>");
                    out.print("</select></td>");
                    out.print("<td><input type=\"text\" name=\"rst_exmresit\" size=\"5\" value=\"NE\"></td>");
                    out.print("<td><input type=\"text\" name=\"rst_exmresult\" size=\"5\" value=\"NE\"></td>");
                  }
                  out.print("</tr>");
                }
                out.print("</table>");
                out.print("</td>");
                out.print("<td><input type=\"submit\" name=\"Submit\" value=\"Confirm\"></td>");
                out.print("<td><input type=\"reset\" name=\"Reset\" value=\"Reset\"></td>");
                out.print("</tr>");
              }
            }
          %>
          </tr>
        </table>
      </form>
    </td>
  </tr>
</table>

我想給每個學生生成一個FORM,submit相對應的數據。
網頁可以正常顯示,但按下“Submit”後網頁就跳出了,數據也沒有post出去。


reply to postreply to post
作者 Re:多個Form的submit問題 [Re:redhobor]
Jill_Yeh

眾裡尋他千百度



發文: 89
積分: 0
於 2005-04-01 01:06 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
第一個, form 不能有階層的關係, 也就是說, form 內不能有其他的 form
第二個, 最外層的 form action="", 有可能這樣才會跳出??
第三個, 不懂跳出是什麼意思, 視窗關閉? 跳到空白畫面?

嗯, 先把第一點修正好, 也許問題就會連帶的一併解決..


reply to postreply to post
作者 Re:多個Form的submit問題 [Re:redhobor]
redhobor





發文: 20
積分: 0
於 2005-04-01 01:43 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
問題我已經解決了,給每個Form加上唯一的ID。
同時謝謝樓上的兄弟或是女士(?Smile


reply to postreply to post
作者 Re:多個Form的submit問題 [Re:redhobor]
redhobor





發文: 20
積分: 0
於 2005-04-02 12:53 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<script type="" language="javascript">
<!--
//This function is used to check mark input.
function isValid() {
  var i, rst_exmfirst, rst_exmhasresit, rst_exmresit;
  for (i=0; i<forms.length; i++) {
    form = document.forms[i];
    if (document.form.rst_exmfirst.value=="") {
      window.alert("Result cannot be null!");
      document.form.rst_exmfrist.focus();
      return false;
    }
    if (document.form.value != "NE") {
      rst_exmfirst = parseFloat(document.form.rst_exmfirst.value);
      if (rst_exmfirst>100) {
        window.alert("Result cannot be over 100!");
        document.form.rst_exmfirst.focus();
        return false;
      }
    }
    if (document.form.rst_exmresit.value =="") {
      window.alert("Result cannot be null!");
      document.form.rst_exmresit.focus();
      return false;
    }
    if (document.form.rst_exmresit.value != "NE") {
      if (document.form.rst_exmhasresit.value == "false") {
        window.alert("This student has no resit! Please check!");
        document.form.rst_exmresit.focus();
        return false;
      }
    }
    if (document.form.rst_exmresit.value != "NE") {
      rst_exmresit = parseFloat(document.form.rst_exmresit.value);
      if (rst_exmresit>100) {
        window.alert("Result cannot be over 100!");
        document.form.rst_exmresit.focus();
        return false;
      }
    }
  }
  form.submit();
}
//-->
  <tr>
    <td height="69" colspan="3">
      <center>
        <table width="100%" border="0">
          <tr bgcolor="#CCCCCC">
            <td width="15%">Student ID</td>
            <td width="15%">Student Name</td>
            <td width="50%">Exam Results</td>
            <td width="10%">Confirm</td>
            <td width="10%">Reset</td>
          </tr>
          <tr>
          <%
            ResultSet rs_student = (ResultSet) studentManage.getAllStudents();
            //Check if any student exists
            //If there has no student information stored in database
            if (rs_student.wasNull()) {
              out.print("<tr>No Information!</tr>");
            }
            //If there has student informaiton stored in database, then displays exam information for each student.
            else {
              int frmNum = 0;
              while (rs_student.next()) {
                out.print("<tr>");
                out.print("<form name=\"" + frmNum + "\" id=\"" + frmNum + "\" method=\"post\" action=\"inputexamservlet\" onsubmit=\"isValid()\">");
                frmNum++;
                std_id = rs_student.getString("std_id");
                std_surname = rs_student.getString("std_surname");
                std_forename = rs_student.getString("std_forename");
                out.print("<td>" + std_id + "</td>");
                out.print("<td>" + std_forename + " " + std_surname + "</td>");
                out.print("<input type=\"hidden\" name=\"mdl_id\" value=\"" + mdl_id + "\">");
                out.print("<input type=\"hidden\" name=\"std_id\" value=\"" + std_id + "\">");
                out.print("<input type=\"hidden\" name=\"std_name\" value=\"" + std_forename + " " + std_surname + "\">");
                out.print("<input type=\"hidden\" name=\"countexam\" value=\"" + countexam + "\">");
                out.print("<td>");
                out.print("<table>");
                out.print("<tr bgcolor=\"#CCCCCC\">");
                out.print("<td width=\"20%\">Exam ID</td>");
                out.print("<td width=\"20%\">First Result</td>");
                out.print("<td width=\"20%\">Has Resit?</td>");
                out.print("<td width=\"20%\">Resit Result</td>");
                out.print("<td width=\"20%\">Final Result</td>");
                out.print("</tr>");
                //Display every exam
                for (int i = 1; i <= countexam; i++) {
                  rst_exmid = Integer.toString(i);
                  out.print("<tr>");
                  out.print("<td>" + rst_exmid + "</td>");
                  out.print("<input type=\"hidden\" name=\"rst_exmid\" value=\"" + rst_exmid + "\">");
                  rstExam = markManage.getResultExm(mdl_id, std_id, rst_exmid);
                  //If this student has had results of exams
                  if (rstExam != null) {
                    rst_exmfirst = rstExam.getRst_exmfirst();
                    rst_exmhasresit = rstExam.getRst_exmhasresit();
                    rst_exmresit = rstExam.getRst_exmresit();
                    rst_exmresult = rstExam.getRst_exmresult();
                    if (rst_exmfirst != -1) {
                      out.print("<td><input type=\"text\" id=\"rst_exmfirst\" name=\"rst_exmfirst\" size=\"5\" value=\"" + rst_exmfirst + "\"></td>");
                    }
                    else {
                      out.print("<td><input type=\"text\" id=\"rst_exmfirst\" name=\"rst_exmfirst\" size=\"5\" value=\"NE\"></td>");
                    }
                    out.print("<td><select id=\"rst_exmhasresit\" name=\"rst_exmhasresit\" size=\"1\">");
                    if (rst_exmhasresit) {
                      out.print("<option selected value=\"true\">Yes</option>");
                      out.print("<option value=\"false\">No</option>");
                    }
                    else {
                      out.print("<option value=\"true\">Yes</option>");
                      out.print("<option selected value=\"false\">No</option>");
                    }
                    out.print("</select></td>");
                    if (rst_exmresit != -1) {
                      out.print("<td><input type=\"text\" id=\"rst_exmresit\" name=\"rst_exmresit\" size=\"5\" value=\"" + rst_exmresit + "\"></td>");
                    }
                    else {
                      out.print("<td><input type=\"text\" id=\"rst_exmresit\" name=\"rst_exmresit\" size=\"5\" value=\"NE\"></td>");
                    }
                    if (rst_exmresult != -1) {
                      out.print("<td><input type=\"text\" id=\"rst_exmresult\" name=\"rst_exmresult\" size=\"5\" readonly value=\"" + rst_exmresult + "\"></td>");
                    }
                    else {
                      out.print("<td><input type=\"text\" id=\"rst_exmresult\" name=\"rst_exmresult\" size=\"5\" readonly value=\"NE\"></td>");
                    }
                  }
                  //If this student has no results of exams
                  else {
                    out.print("<td><input type=\"text\" id=\"rst_exmfirst\" name=\"rst_exmfirst\" size=\"5\" value=\"NE\"></td>");
                    out.print("<td><select id=\"rst_exmhasresit\" name=\"rst_exmhasresit\" size=\"1\">");
                    out.print("<option value=\"true\">Yes</option>");
                    out.print("<option selected value=\"false\">No</option>");
                    out.print("</select></td>");
                    out.print("<td><input type=\"text\" id=\"rst_exmresit\" name=\"rst_exmresit\" size=\"5\" value=\"NE\"></td>");
                    out.print("<td><input type=\"text\" id=\"rst_exmresult\" name=\"rst_exmresult\" size=\"5\" readonly value=\"NE\"></td>");
                  }
                  out.print("</tr>");
                }
                out.print("</table>");
                out.print("</td>");
                out.print("<td><input type=\"submit\" name=\"Submit\" value=\"Confirm\"></td>");
                out.print("<td><input type=\"reset\" name=\"Reset\" value=\"Reset\"></td>");
                out.print("</form></tr>");
              }
            }
          %>
          </tr>

遇到了新問題,怎樣用javascript驗證需要submit的Form?


redhobor edited on 2005-04-02 12:59
reply to postreply to post
作者 Re:多個Form的submit問題 [Re:redhobor]
abgne





發文: 323
積分: 2
於 2005-04-02 13:56 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
可以替需要驗證的物件都設個ID..
再用document.getElementById("xx").value來判斷


reply to postreply to post
作者 Re:多個Form的submit問題 [Re:redhobor]
redhobor





發文: 20
積分: 0
於 2005-04-02 14:30 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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
function isValid(num) {
  var first = document.getElementById("rst_exmfirst"+num).value;
  var hasresit = document.getElementById("rst_exmhasresit"+num).value;
  var resit = getElementById("rst_exmfirst"+num).value;
  if (first == "") {
    window.alert("Result cannot be null!");
    return false;
  }
  if (first != "NE") {
    first = parseFloat(first);
    if (first>100) {
      window.alert("Result cannot be over 100!");
      return false;
    }
  }
  if (resit =="") {
    window.alert("Result cannot be null!");
    return false;
  }
  if (resit.value != "NE") {
    if (hasresit == "false") {
      window.alert("This student has no resit! Please check!");
      return false;
    }
  }
  if (resit.value != "NE") {
    resit = parseFloat(resit);
    if (resit>100) {
      window.alert("Result cannot be over 100!");
      return false;
    }
  }
  submit();
}

動態的element id如何表示?我如上改寫了javascript,但沒有起作用。


reply to postreply to post
作者 Re:多個Form的submit問題 [Re:redhobor]
abgne





發文: 323
積分: 2
於 2005-04-02 16:57 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不知道這樣可以幫到你嗎@@?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<FORM METHOD=POST ACTION="">
<script>
  for(var i = 0 ; i < 10 ;i++){
    document.write("<INPUT TYPE='text' id="+i+"><br>");
  }
</script>
<br>
<INPUT TYPE="submit" value="驗證" onclick="check()">
<script>
  function check(){
    if(document.getElementById("1").value==""){
      alert("沒填寫");
      return false;
    }
  }
</script>
</FORM>


reply to postreply to post
» JWorld@TW »  Web Design 版

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8