首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

javacript如何获取jsp页面中多个name一样的text数据

2012-01-20 
javacript怎么获取jsp页面中多个name一样的text数据?%@pagelanguage java import java.util.* page

javacript怎么获取jsp页面中多个name一样的text数据?
<%@   page   language= "java "   import= "java.util.* "   pageEncoding= "ISO-8859-1 "%>
<%
String   path   =   request.getContextPath();
String   basePath   =   request.getScheme()+ ":// "+request.getServerName()+ ": "+request.getServerPort()+path+ "/ ";
%>
<%@   page   import= "com.accp.dao.* "%>
<%@   page   import= "com.accp.bean.* "%>
<%@   page   import= "java.sql.* "%>
<%
ResultSet   rs=new   enterSubject().selectSub();
String   number=null;
String   subject=null;

  %>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">
<html>
    <head>
        <base   href= " <%=basePath%> ">
       
        <title> My   JSP   'answer.jsp '   starting   page </title>
       
<meta   http-equiv= "pragma "   content= "no-cache ">
<meta   http-equiv= "cache-control "   content= "no-cache ">
<meta   http-equiv= "expires "   content= "0 ">        
<meta   http-equiv= "keywords "   content= "keyword1,keyword2,keyword3 ">
<meta   http-equiv= "description "   content= "This   is   my   page ">
<!--

-->
<script   type= "text/javascript ">
function   checkAnswer()
{
var   answer=document.getElementById( "answer ");
}
</script>
    </head>
      <form   name= "form "   action= "/ExamOnline/CheckAnswer "   onSubmit= "return   checkAnswer() ">
    <table   align= "center ">
    <tr> </tr>
    <%
   
    while(rs.next())
    {
    number=rs.getString( "number ");
    subject=rs.getString( "subject ");
    %>
 
    <tr>
    <td> <%=number%> </td>
    </tr>
    <tr>
    <td> <%=subject%> </td>
    </tr>
    <tr>
    <td> <input   type= "text "   id= "answer "   name= "answer "/> </td>
    </tr>
 
    <%}   %>
    </table>
    </br>
    <input   type= "Submit "   value= "submit "/>
        </form>
    <body>
       
    </body>
</html>

如果我有10条纪录,用户输入答案提交后,如何判断是否有空的答案?
如果有空的答案如何用 "error "填充?

[解决办法]
为什么不把
<td> <input type= "text " id= "answer " name= "answer "/> </td>


这一行改成
<%
i++;
String ans= " <td> <input type=\ "text\ " id=\ "answer "+i+ "\ " name=\ "answer "+i+ "\ "/> </td> "
%>
<%=ans%>
呢,这样只要在前面初始化一个int i=0;
就可以了。
这个时候,名字就不重复了
[解决办法]
对阿,用不同的ID就可以了
[解决办法]
不修改这样也可以
<SCRIPT>
function fnGetNames(){
// Returns a collection with 2 INPUT type=text elements.
var aInput=document.getElementsByName( "firstName ");
//按照从上向下的顺序就能够便利所有的name为firstName的text
alert(aInput[0].value);
alert(aInput[1].value);
}
</SCRIPT>
<INPUT TYPE= "text " NAME= "firstName ">
<INPUT TYPE= "text " NAME= "firstName ">
<INPUT TYPE= "button " VALUE= "Get Names " onclick= "fnGetNames() ">
[解决办法]
jackkui(键 之 舞 者) 说的对
Enumeration a = request.getParameterNames()
while(a.hasMoreElements())
{

String n=(String)a.nextElement();
if( "answer ".equals(n)){
String[] name=request.getParameterValues(n);

for(int i=0;i <name.length;i++)
{
out.print(name[i]+ " <br> ");
}

}}



热点排行