使用javascript将表一值与同一行的另一个值进行比较

时间:2012-10-02 06:56:03

标签: javascript asp-classic

在当前屏幕中,我想使用javascript进行验证

1.用户不应在RO数量中输入负值。和

2. RO数量值应小于出货数量

对于第一次验证,我编写了javascript并在keypress中调用了它     按钮事件。

  function onlyNumeric() {

        if (event.keyCode < 48 || event.keyCode > 57) {
            alert("Invalid RoQuantity,Quantity should not be negative.");
            event.returnValue = false;
        }
    }

它的工作正常,但是当我想为较小的和。添加验证时  在keyup和keydown中更大,那么负值验证不起作用。

对于第二次验证,我试过这样但不是成功的

if (document.getElementById("ROQuantity").value > document.getElementById("shpdqty").innerHTML) {
            alert("Please Enter RO Qty, and ROQty shouldnot be greater then shipped quantity.");
            return false;
        }

这也有效,但只适用于第一行,所以如何在这里使用for循环  适用于所有行。

所以请帮我怎么做。

还有一件事是ASP CLASSIC页面。

这是我绑定值的TR标签。

<tr valign="top" bgcolor="#E9E9E9">
      <td colspan="2" bgcolor="#FFFFFF" scope="col">
        <table width="100%" border="0" cellpadding="10" cellspacing="0" bordercolor="#E5E5E5"
                                        id="ctl00_ContentPlaceHolder1_GV">
            <tr bgcolor="#333333">
               <td scope="col">
                 <strong><font color="#FFFFFF">No</font></strong>
                </td>
                <td align="center" scope="col">
                  <strong><font color="#FFFFFF">Carton</font></strong>
                </td>
                <td scope="col">
                   <strong><font color="#FFFFFF">Article Code </font></strong>
                </td>
                <td align="center" scope="col">
                   <strong><font color="#FFFFFF">Color</font></strong>
                 </td>
                <td align="center" scope="col">
                   <strong><font color="#FFFFFF">Size</font></strong>
                </td>
                <td align="right" scope="col">
                   <strong><font color="#FFFFFF">Order Qty</font></strong>
                </td>
                <td align="center" scope="col">
                   <strong><font color="#FFFFFF">Shipped Qty </font></strong>
                </td>
                <td align="center" scope="col">
                   <strong><font color="#FFFFFF">RO Qty</font></strong>
                </td>
              </tr>
            <tbody>

         <% i =1
            set rs1 = server.CreateObject("adodb.recordset")
            sql1 = "SELECT     tblOrderAllocationListItems.OItemID, tblOrderAllocationListItems.MALItemID, tblOrderAllocationListItems.OrderNo, " & _
                    "tblOrderAllocationListItems.MALNo, tblOrderAllocationListItems.CartonName, tblOrderAllocationListItems.ArticleCode, " & _
                    "tblOrderAllocationListItems.Cup, tblOrderAllocationListItems.ColorID, " & _ 
                    "tblOrderAllocationListItems.SizeID, tblOrderAllocationListItems.UOM, tblOrderAllocationListItems.ArticleCostPrice, " & _
                    "tblOrderAllocationListItems.ArticleRCP, tblOrderAllocationListItems.OrderedQuantity, tblOrderAllocationListItems.ShippedQuantity, tblOrderAllocationListItems.ROQuantity, " & _
                    "tblArticleImage.ImagePath FROM tblOrderAllocationListItems LEFT OUTER JOIN " & _
                    "tblArticleImage ON tblOrderAllocationListItems.ArticleCode = tblArticleImage.ArticleCode where tblOrderAllocationListItems.OrderNo = '" & OrderNo & "' order by tblOrderAllocationListItems.CartonName, tblOrderAllocationListItems.ArticleCode"   
            rs1.Open sql1,strconnect,3,3,&H0001
            while Not rs1.EOF

            if i mod 2 = 0 then
            nbgcolor = "#F3F3F3"
            else
            nbgcolor = "#FFFFFF"
            end if

            orderamt = rs1("OrderedQuantity") * rs1("ArticleCostPrice")
            shippedamt = rs1("ShippedQuantity") * rs1("ArticleCostPrice")
            ShippedVarious = rs1("OrderedQuantity") - rs1("ShippedQuantity") 
            ROamt = rs1("ROQuantity") * rs1("ArticleCostPrice")
                                        %>
                                        <tr bgcolor="<%=nbgcolor%>">
                                            <td>
                                                <%=i%>
                                            </td>
                                            <td align="center">
                                                <font color="#000000">
                                                    <%=rs1("CartonName")%>
                                                </font>
                                            </td>
                                            <td>
                                                <a href="javascript:popup('http://www.anakku.com/v5/products_detail.asp?pro_id=609','photo','scrollbars=yes,resizable=yes,width=400,height=400')">
                                                    <font color="#000000">
                                                        <%=rs1("ArticleCode")%>
                                                    </font></a>
                                            </td>
                                            <td align="center">
                                                <a href="javascript:popup('http://www.anakku.com/v5/products_detail.asp?pro_id=609','photo','scrollbars=yes,resizable=yes,width=400,height=400')">
                                                    <font color="#000000">
                                                        <%=rs1("ColorID")%>
                                                    </font></a>
                                            </td>
                                            <td align="center">
                                                <font color="#000000">
                                                    <%=rs1("SizeID") & "/" & rs1("Cup")%>
                                                </font>
                                            </td>
                                            <td align="right" bgcolor="#D9D9FF">
                                                <font color="#000000">
                                                    <%=rs1("OrderedQuantity")%>
                                                </font>
                                            </td>

//我想比较这两个TD

               <td align="center" bgcolor="#C6FFC6" id="shpdqty">
                     <%=rs1("ShippedQuantity")%>
                </td>
               <td align="center" bgcolor="#D5E6FF">
                  <input name="ROQuantity<%=rs1("OItemID")%>" type="text" value="<%=rs1("ROQuantity")%>"
                                                    id="ROQuantity" size="5" onkeypress="onlyNumeric();" />
                                            </td>

                                        </tr>
                                        <%
            tOrderedQuantity = tOrderedQuantity + rs1("OrderedQuantity")                
            tShippedQuantity = tShippedQuantity + rs1("ShippedQuantity")                
            tShippedvariousQuantity = tShippedvariousQuantity + ShippedVarious              
            tROQuantity = tROQuantity + rs1("ROQuantity")
            tROamt = tROamt + ROamt

            i = i + 1
            rs1.movenext
            wend
            rs1.close
            set rs1 = nothing                   
                                        %>
                                        <tr style="color: #333333; background-color: white">
                                            <td colspan="5" align="right">
                                                <strong>Total Qty</strong>
                                            </td>
                                            <td align="right" bgcolor="#AEAEFF">
                                                <strong>
                                                    <%=tOrderedQuantity%>
                                                </strong>
                                            </td>
                                            <td align="center" bgcolor="#AAFFAA">
                                                <strong>
                                                    <%=tShippedQuantity%>
                                                </strong>
                                            </td>
                                            <td align="center" bgcolor="#AEAEFF">
                                                <font color="#000000">
                                                    <%=tROQuantity%>
                                                </font>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </td>
                        </tr>

1 个答案:

答案 0 :(得分:0)

将其更改为:

if (parseInt(document.getElementById("ROQuantity").value) > parseInt(document.getElementById("shpdqty").innerHTML)) {