how to validate all but not single pair of input box in jQuery

Posted by I Like PHP on Stack Overflow See other posts from Stack Overflow or by I Like PHP
Published on 2010-03-09T08:57:04Z Indexed on 2010/03/09 11:06 UTC
Read the original article Hit count: 187

Filed under:
|

i have a form which have 45 input boxes, i applied jquery validation for all input boxes , but there is two pair of input boxes which have either oneof them should be filled up, not both. so how do i change jquery so that if anyone fill up first pair then jquery does not check second pair of input box and if any one is fill up second pair then not check for fisrt one's and also i have used radio box for showing one pair at a time

i show code below:

jQuery Code

<script type="text/javascript">
$j=jQuery.noConflict();
    $j(document).ready(function()
    {
        function validate() {
        return $j("input:text,textarea,select,radio").removeClass('rdb').filter(function() {
        return !/\S+/.test($j(this).val());
         }).addClass('rdb').size() == 0;
    }
    $j('#myForm').submit(validate); 
    $j(":input:text,textarea,select").blur(function() {
    if(this.value.length > 0) {
        $j(this).removeClass('rdb');
    }
    });
    $j("input:radio").click(function(){
        if($j(this).val()=='o'){
            $j("#rcpt").css("display","none");
            $j("#notRcpt").css("display","inline");         
        }
        if($j(this).val()=='r'){
            $j("#notRcpt").css("display","none");
            $j("#rcpt").css("display","inline");            
        }
    });
}); 
</script>

PHP Code

<form name="myForm" action="somepage.php" method="post" id="myForm">
<table width="100%" border="0" cellspacing="4" cellpadding="0">
    <tr>
       <td class="boxtitle">Delivery Pick up Station/Place</td>
    <tr>
        <td style="font:bold 11px verdana;"> 
            <input type="radio" name="receipt" value="r" >Receipt
            <input type="radio" name="receipt" value="o" >Other 
        </td>
    </tr>
    <tr>
        <td>
           <table width="100%" border="0" cellspacing="3" cellpadding="0">
           <tr id="rcpt" style="display:none">
                <td width="12%" align="left">Receipt:</td>
                <td width="30%" align="left"<input type="text" name="deliveryNo" id="deliveryNo" /></td>
                <td width="25%" align="right">Pick up Date:</td>
                <td width="35%" align="left"><input name="deliveryDate" type="text" id="deliveryDate" /></td>
           </tr>                            
           <tr id="notRcpt" style="display:none">
                <td>Other:</td>
                <td><input name="deliveryNo" type="text" id="deliveryNo" /></td>
                <td align="right">Pick up Date:</td>
                <td><input name="otherDeliveryDate" type="text" id="otherDeliveryDate" /></td>                              
           </tr>
          </table>
        </td>
    </tr>
</table>
</form>

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery