doukang7858 2018-01-31 13:53 采纳率: 0%
浏览 21

如何在php中验证循环值? 第1栏>第2栏

enter image description here

The above image due value 19948 and the input value are not greater than the due value 19948. How to validate this in javascript or jquery or php?

<?php
$i = 0;
$sql = "select * from invoice where `cid`='5'";
$res = mysql_query($sql);
$numrows = mysql_num_rows($res);
while ($row = mysql_fetch_array($res)) {

        $i = $i + 1;

        echo "<tr>";

        echo "<td>" . $row['customername'] . "</td>";
        echo "<td>" . $row['totalamount'] . "</td>";
        echo "<td>" . $row['paidamount'] . "</td>";
        echo "<td>" . $row['dueamount'] . "</td>";

        ?>


        <?php

        echo "<td><input type='text' name='ichange$i' value='0'  onkeyup='ivalue()'  />
                      <input type='hidden' name='idue$i' value='$due'   /></td>";
        echo "</td>"; 

        echo "</tr>";

}

 echo "<input type='hidden' name='nrows' value='$numrows' />";

?>

 <script>

     function ivalue()
    {

        nrows=document.getElementsByName("nrows").item(0).value;

        for(i=1;i<=nrows;i++)
        {
            ichange="ichange" + i;
            idue="idue" + i;

            if(document.getElementsByName(ichange).item(0).value>document.getElementsByName(idue).item(0).value)    
            {
               alert("Value not greater than due value")

            }


        }


    } 

</script>
  • 写回答

1条回答 默认 最新

  • duanmangxie7131 2018-01-31 16:12
    关注

    I suppose you want to alert the user if he enters a greater value than the due in the same row. I would use jQuery here since you tagged it :

    $('input[type="text"]').on('keyup',function(){
        if($(this).val() > $(this).next().val()){
            alert("Value not greater than due value")
        }
    })
    

    You could add some classes to your html for an easier and more precise select.

    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源