不好意思写错了一个字。一组动态的复选框和相对应的一组文本框.
如:
   S 复选框1      A文本框1
   S 复选框2      A文本框2
   S 复选框3      A文本框3
   S 复选框4      A文本框4
其中S为复选框的Name属性,A为文本框的Name属性.
现在我要得来当选中第一个和第三个复选框时,同时也要求出与它们相对应的第一个和第三个文本框的内容.该如何做呢?请大家多多指教.

解决方案 »

  1.   

    <script>
    function checkedit(form,len){
    var isnull;
    isnull = false;   
    for(i=0;i<form.elements.length;i++){  
    if(form.elements[i].type=="checkbox"&&form.elements[i].name=="checkit"){
    if(form.elements[i].checked==true){
    alert(form.elements[i+1].value);
    isnull = true;
    }
    }
    }
    if(isnull == false){
    alert("no select ");
    }

    }
    </script>
    <form name= "test123"><br>
    <input type= "checkbox" name= "checkit"><input type= "text" name= "textit" value= "1"><br>
    <input type= "checkbox" name= "checkit"><input type= "text" name= "textit" value= "2"><br>
    <input type= "checkbox" name= "checkit"><input type= "text" name= "textit" value= "3"><br>
    <input type= "checkbox" name= "checkit"><input type= "text" name= "textit" value= "4"><br>
    <input type= "button" name= "button" value= "button" onclick= "javascript:checkedit(this.form,1)"><br>
    </form>
      

  2.   

    <html>
    <head>
    <title>还款核准</title>
    <link href="include/main.css" rel="stylesheet" type="text/css">
    </head>
    <script language="JavaScript">
    <!--function getValue(ckb)
    {
    if(!ckb.checked) return;
    ckbAffix = "ckb_";
    txtAffix = "txt_";
        idx =  ckb.name.substring(ckbAffix.length);
    txtName = "document.form1." + txtAffix + idx + ".value";
        alert(txtName);
        txtValue = eval(txtName);
    alert(txtValue);
    }
    //-->
    </script>
    <body bgcolor="#FFFFFF" text="#000000"><form name="form1" method="post">
    <input type="checkbox" name="ckb_01" value="0" OnClick="getValue(this);">
    <input type="text" name="txt_01" value="0">
    <input type="checkbox" name="ckb_02" value="0" OnClick="getValue(this);">
    <input type="text" name="txt_02" value="0">
    </form>
    </body>
    </html>
      

  3.   

    我觉得这个不能写死了,应该都是动态的。
    checkbox命名cCheck+i,同理text命名:txtNum+i,i是变量,自动加1的。
    同时把这个i值放在hidden input里面发到接收页。
    然后在接收页面里根据这个i值判断,如果接收到的cChecki!=null,则去接收txtNumj的值。另外在提交页可以这样判断,如果用户选了checkbox,而没有在对应的text里输值,哪就alert提示他,如果都为空,可以不管。写这么个javascript不难吧,参照一楼的改写一下就行!
      

  4.   

    kaibinsj(天翔)说的有点道理,但这样一来,在客户端就判断不出它是否被选中。
      

  5.   

    <%
    int j=0;
    while(rs.next()){
    LocateNo1=str(rs.getString("Lod_LocateNo"));
    %> 
         <tr> 
            <td width="35%" align="right">&nbsp;
     <input type="checkbox" name="Select" value="<%=rs.getInt("Lod_ID")%>" >
    </td>
              <td width="30%" align="left">&nbsp;<%=str(rs.getString("Lod_LocateNo"))%></td>
              <td width="10%" align="right">&nbsp;<%=ddf.format(rs.getDouble("Lod_Balance"))%></td>
               <td width="25%" align="center">&nbsp;
        <input type="text" name="Amount" style="text-align:right;width:50%" onKeyPress="CheckFloat(this)" onFocus="init(this)" class="input" >
        <input type="hidden" name="na" value="<%=str(rs.getString("Lod_LocateNo"))%>">
        <input type="hidden" name="ye" value="<%=ddf.format(rs.getDouble("Lod_Balance"))%>">
    </td>
                    </tr>
    <%
    j++;
    }%>  
    function Select1() //更新入庫
    {  
       var Amount=f1.Amount1.value;
       var TeAmount=0;
       var TotalAmount=0;
       var l=f1.Select.length;
       var Flag=false;

     if(isNaN(l)){
       if(f1.Select.checked){
          Flag=true;
      TotalAmount=parseFloat(f1.Amount.value);
      //alert("testAmount="+TotalAmount);
       }
     }else if(l>1){
        for(var i=0;i<l;i++){
          if(f1.Select[i].checked){
            Flag=true;
    TotalAmount+=parseFloat(f1.Amount[i].value);
      }
    }
        //alert("a="+TotalAmount);
     }
     //equals Amount
       if(parseFloat(TotalAmount)>parseFloat(Amount)){
          alert("您輸入的數大于入庫數量");
    Flag=false;
       }
       if(parseFloat(TotalAmount)<parseFloat(Amount)){
          alert("您輸入的數小于入庫數量");
    Flag=false;
       }
     if(Flag){
        if(confirm("您确實要操作這些記錄嗎?")){
      f1.action="payment_save.jsp";
      f1.submit();
      //alert("操作成功!");
      //window.close();
      
      //return true;
    }
     }
     //else{
     //alert ("您輸入的數不等于入庫數量,或者沒有選擇要操作的記錄。");
      //}
    }
      

  6.   

    getValue(ckb)只是引出个思路,意思是当你选中checkbox时可以取得其相应的text的值。
    如果要提交到后台,方法类似于getValue(ckb)。
    1、如果checkbox、text的命名如一楼,可以根据表单名称取得参数数组,然后循环就可以了。
    2、如果checkbox、text的命名是以前缀+序号,则需要页面传入一个最大序号值,再通过循环判断取值。
    如何应用,根据具体情况而定吧。
      

  7.   

    现在就是在保存页面,若选择第一个和第三个复选框是,文本框相应的第一个和第三的值取不到。保存页面是这样的。
    save.jsp   String[] Select1=request.getParameterValues("Select");
       String[] Amount=request.getParameterValues("Amount");
       String   TotalAmountIn=request.getParameter("TotalAmountIn");
       String   Status="";
       String   countstatus="";
      int      len=Select1.length;
      int[]    LodID=new int[len];
      double[] Balance=new double[len];
      double[] AmountBalance=new double[len];
      double[] ToAmount=new double[len];
      double   AllMtlBalance=0;
      double   AllBalance=0;
      double   MtlBalance=0;
      double   AllAmount=0;
      double   TransactionAmount=0;
      out.print("len="+Select1.length+"<br>");
      out.print("Amount="+Amount.length+"<br>");
     
         for(int i=0;i<Select1.length;i++)
        { 
      if(Amount[i]!=null && !Amount[i].equals("")){
             ToAmount[i]=Double.valueOf(Amount[i]).doubleValue();
      }
      out.print("ToAmount["+i+"]="+ToAmount[i]+"<br>");
      
      sql="select * from tLocateDetail where Lod_ID='"+Select1[i]+"'";
      rs=stmt.executeQuery(sql);
      if(rs.next()){
         Balance[i]=rs.getDouble("Lod_Balance");
      }
       AmountBalance[i]=Balance[i]+ToAmount[i];
       out.print("AmountBalance[i]="+AmountBalance[i]+"<br>");
       
           // update tLocateDetail
          sql="update tLocateDetail set Lod_Balance='"+AmountBalance[i]+"' where Lod_ID='"+Select1[i]+"' ";
          stmt.executeUpdate(sql);
      out.print("update tLocateDetail="+sql+"<br>");
      
          // insert tFormDetailTransaction
          sql="insert into tFormDetailTransaction (Fdt_Transaction,Fdt_Num,Fdt_LodID) values('"+FormDetailID+"','"+ToAmount[i]+"','"+Select1[i]+"')";
          stmt.executeUpdate(sql);
      out.print("insert tFormItem="+sql+"<br>");
      
      AllAmount+=ToAmount[i];
      out.print("AllAmount="+AllAmount+"<br>");
      }
      

  8.   

    //发送页
    <script>
    function checkpro(){
    i = 1;
    while(eval(document.all["cCheck"+i])){
    if (document.all["cCheck"+i].checked == true){
    if (isNaN(document.all["txtNumber"+i].value)){
    alert("第" + i + "个数量值:请输入数字");
    return false;
    }
    }
    i++;
    }
    return true;

    }
    </script><td>
    <input name=<%out.print("cCheck"+j);%> type="checkbox"  value="<%out.print(rs.getString("productName")%>"> 
                      </td>
                      <td> <input name=<%out.print("txtNumber"+j);%> type="text" size="10" maxlength="5" value="<%=rs.getInt("totalnum")%>"> 
                      </td>
    <input type="hidden" name="passNum" value=<%=j%>> //这里j可以从分页的记录数得到
    //接收页
    /*传过来的cCheck数量*/
    int passNum = Integer.parseInt(request.getParameter("passNum")); for(int i=1;i<passNum;i++){
    chksign = "cCheck"+i;  //out.print("chksign: "+chksign+"<br>");

    getID = request.getParameter(chksign);

    if(getID==null){getID ="";}
    else{
    getID = new String(request.getParameter(chksign).getBytes("ISO8859_1"),"GBK");
    }
    //out.print("getID: "+getID+"<br>");

    if(getID!=null &&(!getID.equals(""))){
    txtsign = "txtNumber"+i;
    orderNum = request.getParameter(txtsign);  //得到订货数量
      

  9.   

    String[] Select1=request.getParameterValues("Select");
       String[] Amount=request.getParameterValues("Amount");
       String   TotalAmountIn=request.getParameter("TotalAmountIn");
       String   Status="";
       String   countstatus="";
      int      len=Select1.length;
      int[]    LodID=new int[len];
      double[] Balance=new double[len];
      double[] AmountBalance=new double[len];
      double[] ToAmount=new double[len];
      double   AllMtlBalance=0;
      double   AllBalance=0;
      double   MtlBalance=0;
      double   AllAmount=0;
      double   TransactionAmount=0;
      out.print("len="+Select1.length+"<br>");
      out.print("Amount="+Amount.length+"<br>");
     
         for(int i=0;i<Select1.length;i++)
        { 
      if(Amount[i]!=null && !Amount[i].equals("")){
             ToAmount[i]=Double.valueOf(Amount[i]).doubleValue();
      }
      out.print("ToAmount["+i+"]="+ToAmount[i]+"<br>");
      
      sql="select * from tLocateDetail where Lod_ID='"+Select1[i]+"'";
      rs=stmt.executeQuery(sql);
      if(rs.next()){
         Balance[i]=rs.getDouble("Lod_Balance");
      }
       AmountBalance[i]=Balance[i]+ToAmount[i];
       out.print("AmountBalance[i]="+AmountBalance[i]+"<br>");
       
           // update tLocateDetail
          sql="update tLocateDetail set Lod_Balance='"+AmountBalance[i]+"' where Lod_ID='"+Select1[i]+"' ";
          stmt.executeUpdate(sql);
      out.print("update tLocateDetail="+sql+"<br>");
      
          // insert tFormDetailTransaction
          sql="insert into tFormDetailTransaction (Fdt_Transaction,Fdt_Num,Fdt_LodID) values('"+FormDetailID+"','"+ToAmount[i]+"','"+Select1[i]+"')";
          stmt.executeUpdate(sql);
      out.print("insert tFormItem="+sql+"<br>");
      
      AllAmount+=ToAmount[i];
      out.print("AllAmount="+AllAmount+"<br>");
      }