Javascript 使用复选框和文本字段在动态php网格上进行验证

Javascript 使用复选框和文本字段在动态php网格上进行验证,javascript,php,jquery,mysql,validation,Javascript,Php,Jquery,Mysql,Validation,我有以下数据显示从数据库,它是不确定的 <table class="table-style-one" width="90%" border="0" cellspacing="1" cellpadding="1" style="margin:0 auto;"> <thead style="col

我有以下数据显示从数据库,它是不确定的

<table class="table-style-one" width="90%" border="0" cellspacing="1" cellpadding="1" style="margin:0 auto;">
              
              <thead style="color:black;">
                <th style="text-align:center;">S.N</th>
                <th style="text-align:center;">PO REFERENCE</th>
                <th style="text-align:center;"><strong>ITEM NAME</strong></th>
                <th style="text-align:center;"><strong>UNIT</strong></th>
                <th style="text-align:center;"><strong>QUANTITY IN STOCK</strong></th>
                <th style="text-align:center;"><strong>FROM THIS</strong></th>
                <th style="text-align:center;"><strong>THIS QUANTITY</strong></th>
              </thead>
              <tbody>
                <?php
                $i=1;
        while($rs_rows=mysql_fetch_array($result_of_SQL_GET_POREF_FOR_ITEM))
                {
                  ?>
                  <tr <?=$bg?>>
                    <td align="center" style="padding-top:5px;">
                      <?=$i?>
                    </td>
                    <td width="54%" align="center" style="padding-top:5px;"> <font color="#000000"><?=$rs_rows['po_reference_name'];?>
                    </font> </td>
                    <td width="54%" align="center" style="padding-top:5px;"> <font color="#000000"><?=$rs_rows['item_name'];?>
                    </font> </td>
                    <td width="54%" align="center" style="padding-top:5px;"> <font color="#000000"><?=$rs_rows['unit_name'];?>
                    </font> </td>
                    <td width="54%" align="center" style="padding-top:5px;"> <font color="#000000"><?=$rs_rows['Total_Quantity'];?></font></td>
                    <td width="54%" align="center" style="padding-top:5px;"> <font color="#000000">
                      <input type="checkbox" name="check_list[]" value="<?=$rs_rows['po_refrence_id'];?>">
                    </font></td>
                    <td width="54%" align="center" style="padding-top:5px;">
                      <font color="#000000"><input type="text" name="txt[<?=$rs_rows['po_refrence_id'];?>]"></font>
                    </td>
                  </tr>
                  <?php
                  $i++;
                }
                ?>
                <tr class="text">
                  <td colspan="7"><div align="center">
                    <p>
                      <input type="hidden" name="req" value="<?=$req?>">
                      <input type="submit" name="save" value="Save" class="submit" tabindex="3"  >
                      <input type="reset" name="Reset" value="Cancel" class="submit" tabindex="4">
                      <?php
                      if(isset($_GET[msg])) echo "<font color=red>".$_GET[msg]."</font>";
                      // if(isset($messsag)) echo $messsag;

                      ?>
                    </p>
                  </div></td>
                </tr>
              </tbody></table>

S.N
采购订单参考
项目名称
单位
库存数量
来自此
此数量

您可以通过使用jquery验证插件来实现这一点。 您需要调用jqueryvalidate插件的远程方法,该方法的工作原理与ajax相同。 以便检查用户在文本字段中输入的数量是否小于库存数量

if(isset($_POST['save']))
{
  if ($_GET[add]==0)
  {
    if($_GET['req']=="") $abc= $_POST['req'];
    if($_POST['req']=="") $abc= $_GET['req'];
    echo $abc;
    $quantity_issued = $qty;
    foreach($_POST['check_list'] as $selected){
      foreach ( $_POST['txt'] as $key => $value )
      {
        echo 'Textbox #'.htmlentities($key).' has this value: ';
        echo htmlentities($value);
      }
      $SQL_Query_Get_Item_Quantity = mysql_query("SELECT * FROM stock WHERE po_refrence_id = '".$selected."'");
      if($SQL_Query_Get_Item_Quantity === FALSE){
        die(mysql_error());
      }
      else{
        $result_SQL_Query_Get_Item_Quantity = mysql_fetch_assoc($SQL_Query_Get_Item_Quantity);
        if($quantity_issued > $result_SQL_Query_Get_Item_Quantity['quantity'] && $result_SQL_Query_Get_Item_Quantity['quantity'] != 0){
          echo 'quantiy you want to issued is more than the quantity that this po refrence holds';
        }
        else{
          //echo $result_SQL_Query_Get_Item_Quantity['quantity']."</br>";
          echo 'quantiy you want to issued is less than the quantity that this po refrence holds';
        }
      }

    }
 $( "#myform" ).validate({
  rules: {
    email: {
      required: true,
      email: true,
      remote: "check-email.php"
    }
  }
});