jQuery确认框

时间:2013-01-20 01:34:11

标签: php jquery

我有一个循环,通过复选框输入输入,如果一切正常,它需要显示一个弹出框询问用户是否可以继续并提交订单,如果没有那么它需要做什么都没有(在其中处理)

我遇到了一些问题,无法弄清楚如何做,有什么想法吗?

这是我当前的代码

    function validateSubmit(){
        var r=true;

       $('tr').each( function() {
          // Find first input
          var input1 = $(this).find('input').eq(0);
          var qty1 = input1.val();
          // Find Second input
          var input2 = $(this).find('input').eq(1);
          var qty2 = input2.val();
          // Find third input
          var input3 = $(this).find('input').eq(2);
          var qty3 = input3.val();
          // Find select box
          var selectBx = $(this).find('select');
          var selectVal = selectBx.val();
            if(qty1 === '' && selectVal != 'Please Select...') {
                alert("You've chosen an option, but not entered a quantity to dispute, please check your inputs.");
                r=false;return false;           
            }
            if(qty1 != '' && selectVal === 'Please Select...') {
                alert("You've entered a quantity, but not chosen why, please check your reasons.");
                r=false;return false;       
            }
            if (qty1 > qty2) {
                alert("For one of your entries, the disputed quantity is larger than the shipped quantity.");
                r=false;return false;               
            }
       }); 
           if (r==true) {
            var a = confirm("Are you sure you want to confirm the dispute? You cannot edit this after it's been submitted?");
            if (a==true)
            {
                return true;        
            }
            else
            {
                return false;
            }
}

    });

HTML:

<table>
                <thead>
                    <tr><th>Item ID</th><th>Description</th><th>Dispute Quantity</th><th>Shipped Quantity</th><th>Ordered Quantity</th><th>Reason</th></tr>
                </thead>
                <tbody>
                    <?php
                        $data = mysql_query("SELECT * FROM `artran09` WHERE `invno` = '$invoiceno'") or die(mysql_error());
                        echo "<center>";
                        $i = -1;        
                        echo "<form action=\"submitdispute.php?invno=".$invoiceno."&ordate=".$placed."\" method=\"POST\" onsubmit=\"return validateSubmit();\">";

                            while ($info = mysql_fetch_array($data)) {              
                                $i += 1;                                    
                                echo "<tr>"; 
                                echo "<td>".$info['item']."</td>"; 
                                echo "<td>".$info['descrip']."</td>";       

                                echo "<td><input type=\"text\" input name=".$i." onKeyPress=\"return numbersonly(this, event)\"  maxLength=\"3\"></td>"; 

                                echo "<td><input type=\"text\" value=".$info['qtyshp']." name = \"ship$i\" onKeyPress=\"return numbersonly(this, event)\" maxLength=\"3\" disabled=\"disabled\"></td>"; 

                                echo "<td><input type=\"text\" value=".$info['qtyord']." onKeyPress=\"return numbersonly(this, event)\" maxLength=\"3\" disabled=\"disabled\"></td>"; 

                                echo "<td><select name = \"reason$i\">";
                                echo "<option>Please Select...</option>";
                                echo "<option>Short/Not received</option>";
                                echo "<option>Damaged Goods</option>";
                                echo "<option>Product Not Ordered</option>";                    
                                echo "</select></td>";

                                echo "</tr>"; 
                            }

                    ?>
                </tbody>
            </table>
        </div>
    </div>
    <p><input type = "submit" value = "Dispute" name ="Submit">
    </form>

对于任何有兴趣的人 - 我已经解决了这个问题! 谢谢大家的耐心!这是修复:

   function validateSubmit(){
    var r=true;

   $('tr').each( function() {
      // Find first input
      var input1 = $(this).find('input').eq(0);
      var qty1 = input1.val();
      // Find Second input
      var input2 = $(this).find('input').eq(1);
      var qty2 = input2.val();
      // Find third input
      var input3 = $(this).find('input').eq(2);
      var qty3 = input3.val();
      // Find select box
      var selectBx = $(this).find('select');
      var selectVal = selectBx.val();
        if(qty1 === '' && selectVal != 'Please Select...') {
            alert("You've chosen an option, but not entered a quantity to dispute, please check your inputs.");
            r=false;return false;           
        }
        if(qty1 != '' && selectVal === 'Please Select...') {
            alert("You've entered a quantity, but not chosen why, please check your reasons.");
            r=false;return false;       
        }
        if (qty1 > qty2) {
            alert("For one of your entries, the disputed quantity is larger than the shipped quantity.");
            r=false;return false;           
        }
   }); 

    if (r=true) {
        var a = confirm("Are you sure you wish to dispute? You cannot dispute this order again once submitted.");
        return a;       
    }
}

帮助大家赞赏!

1 个答案:

答案 0 :(得分:1)

答案:

    function validateSubmit(){
    var r=true;

   $('tr').each( function() {
      // Find first input
      var input1 = $(this).find('input').eq(0);
      var qty1 = input1.val();
      // Find Second input
      var input2 = $(this).find('input').eq(1);
      var qty2 = input2.val();
      // Find third input
      var input3 = $(this).find('input').eq(2);
      var qty3 = input3.val();
      // Find select box
      var selectBx = $(this).find('select');
      var selectVal = selectBx.val();
        if(qty1 === '' && selectVal != 'Please Select...') {
            alert("You've chosen an option, but not entered a quantity to dispute, please check your inputs.");
            r=false;return false;           
        }
        if(qty1 != '' && selectVal === 'Please Select...') {
            alert("You've entered a quantity, but not chosen why, please check your reasons.");
            r=false;return false;       
        }
        if (qty1 > qty2) {
            alert("For one of your entries, the disputed quantity is larger than the shipped quantity.");
            r=false;return false;           
        }
   }); 

    if (r=true) {
        var a = confirm("Are you sure you wish to dispute? You cannot dispute this order again once submitted.");
        return a;       
    }
}