如何为完整表单应用onsubmit()表单的多个验证,以及比较两个文本字段,如最大和最小文本字段

时间:2014-12-19 07:33:49

标签: javascript php jquery

这些是用于输入最小和最大文本值的文本文件。

<input type="text" name="min_rent" id="min_rent" placeholder="Min Rent" pattern="[0-9]+" style="width:75px" maxlength="15" required />                       

 <input type="text"  name="max_rent" id="max_rent" placeholder="Max Rent" style="width:75px;" pattern="[0-9]+" maxlength="15" onkeydown="check()" required />

这是提交按钮

<input type="submit" name="continue1" id="continue1" value="Submit" style="margin-left:10px;"/>

并形成标记行

 <form action="<?php echo site_url().'/customer_varad/rent_in_success';?>" name="frm" id="frm" method="post" onsubmit="check_validation();">

这些是我的jquery验证

    <script>
    function check()
    {
    var un = $('#min_rent').val();
     var un1 = $('#max_rent').val();
     if(un>=un1)
     {
    $('#msg').html('Please Enter Maxmum Rent').show();
           }else{
             $('#msg').html('').hide();
           }

    }

    </script>

    function check_validation()
            {

        var un2 = $('#min_rent').val();
     var un3 = $('#max_rent').val();
     if(un2>=un3)
     {
    $('#msg').html('Please Enter Maxmum Rent').show();
           }else{
             $('#msg').html('').hide();
           }

    }

            if(!$('#frm').valid()){

                alert('Please Fill Mandatory Fields');
                $(".div-personal").fadeIn();
                $("#li-personal").animate({opacity:1});
                return false;
            } 
            if($('#frm').valid()){          alert('Details Are Entered Successfully!');

                                                                  //$(".div-property-details").fadeIn();
                return true;
            }
            }




     $('#r_type').change(function(){
          if ($('#r_type').val() == "2" || $('#r_type').val() == "3" || $('#r_type').val() == "4" || $('#r_type').val() == "5" || $('#r_type').val() == "8" || $('#r_type').val() == "10" || $('#r_type').val() == "14" )  {
                $('#floor').hide();

             } else {
                $('#floor').show();

            }
        });



    var un = $('#min_rent').val();
           if(!un && un.length <= 0){
             isValid = false;
             $('#msg_min_rent').html('Please Select Minimum Rent').show();
           }else{
             $('#msg_min_rent').html('').hide();
           }
           //validate max Rent
            var un1 = $('#max_rent').val();
           if(!un1 && un1.length <= 0){
             isValid = false;
             $('#msg_max_rent').html('Please Select Maximum Rent').show();
           }else{
             $('#msg_max_rent').html('').hide();
           }             
    </script>

what more do I add to the code and how do I arrange and place the function check so that along with rest of the validation I can even check minimum and maximum value validation
and this is my rule statements code

<script type="text/javascript">
    $('#frm').validate({
                       rules:
                       {
                           uname:{required:true},
                           one_contact: { required: true,minlength:10,maxlength:10},
                           prop_location:{required: true},
                           per_city:{required: true},
                           //alt_contact: { required: true,minlength:10,maxlength:10},
                           //pre_address: {required: true},
                           //parman_address: {required: true},
                           //member:{required:true},
                           //dob: {required: true},
                           email_id:{required:true, email:true},
                           organization: {required: true},
                           r_type:{required:true},
                            location:{required:true},
                            city:{required:true}
                          // desig: {required: true},
                           //org_contact: {required: true,minlength:10,maxlength:10}
                       },
                       messages:
                       {
                           uname:{required:'Enter Name'},
                           one_contact: {required: 'Enter Mobile No',minlength : 'Minimum 10 Characters', maxlength : 'Maximum 10 Characters'},
                           prop_location:{required:'Select Location'},
                           per_city:{required:'Select City'},// alt_contact: {required: 'Please Insert Mobile No',minlength : ' Mobile No Minimum 10 Characters ',maxlength : ' Mobile No Maximum 10 Bharacters '},
                          // pre_address: {required: 'Enter Present Address'},
                           //parman_address: {required: 'Enter parmanant Address'},
                          // member:{required:'Enter family member'},
                          // dob: {required:'Enter Date of Birth'},
                           email_id:{required:'Enter Email Address'},
                           organization: {required: 'Enter Organization Name'},
                           r_type: {required:'Select Requirement Type'},
                          location: {required:'Select Location'},
                          city: {required:'Select City'}

                          // desig: {required: 'Enter Designation'},
                          // org_contact: {required: 'Please Insert Organisation Mobile No',minlength : ' Mobile No Minimum 10 Characters ',maxlength : ' Mobile No Maximum 10 Bharacters '}
                       }



                       });
    </script>

甚至帮助处理规则如何编写。

提前感谢。

0 个答案:

没有答案