第二页表单的JQuery表单验证问题

时间:2015-10-14 10:45:19

标签: javascript jquery forms validation

我无法通过jquery获取表单验证。

页面上有两个表单,一个隐藏,按下按钮时按下(这一个有效),主联系表单只验证名字字段。

这是我想要使用的表单代码。

    <form method="post" name="new-form" id="new-form" action="http://rpm.runway.com.au/actions/form/globalformaction.jsp" class="contactform">
<div class="new-form">
<div class="formblock">
    <label class="lbl">First Name*</label> <input type="text" id="FirstName" name="FirstName" class="reginput" /></div></div>
</div>

<div class="formblock">
    <label class="lbl">Last Name*</label> <input type="text"  id="LastName" name="LastName"  class="reginput"/>
</div>

<div class="formblock">
    <label class="lbl">Email*</label> <input type="email" id="Email" name="Email"  class="reginput" />
</div>

<div class="formblock">
   <label class="lbl">Phone*</label> <input type="text" id="Mobile"  name="Mobile"  class="reginput" />
</div>  

<div class="formblock">
  <label class="lbl">Source of Enquiry*</label>
    <select id="Answer0F1M413K11419D8M20081M8S3K5Q" name="Answer0F1M413K11419D8M20081M8S3K5Q">
    <option value="">Please select</option>
    <option>Online</option>
    <option>realesate.com.au </option>
    <option>Facebook / Social Media</option>
    <option>Signage</option>
    <option>Builder</option>
    <option>Newspaper</option>
    <option>Word of mouth</option>
    <option>Other</option>
    </select>
    </div>

<div class="formblock">
  <label class="lbl">Postcode* </label> <input type="text" id="Postcode"  name="Postcode"  class="reginput" />
</div>

<div class="formblock">
    <div class=""><label class="lbl">Enquiry</label> <textarea  class="reginput"></textarea></div>
</div>

这是Jquery代码。

<script type="text/javascript">
        jQuery(document).ready(function($){
            $('.btn-register').click(function(){
                    $('.regform').fadeIn('slow');
            });
            $('.close').click(function(){
                    $('.regform').fadeOut('slow');
            });

            $('.contact-us-form').click(function(){
                    $('.contact-us-panel').toggle('slow');
            });
        });

        jQuery(document).ready(function($) {

jQuery('#new-form').change(function() {
 var value1= jQuery('#FirstName').val(); // or $(this).val()
 var value2= jQuery('#LastName').val(); // or $(this).val()
 var value3= jQuery('#Email').val();
 var value4= jQuery('#Mobile').val();
 var value5= jQuery('#Source').val();
 var value6= jQuery('#Postcode').val();
 });
  // validate the comment form when it is submitted
  jQuery("#new-form").validate({
        rules: {

            FirstName: "required",
            LastName: "required",
            Email: { required:true, email:true } ,   
            Mobile: "required",
            Source: "required",
            State: "required",
            Postcode: "required",

        },
        messages: {
            FirstName: "required",
            LastName: "required",
            Email: "required",   
            Mobile: "required",
            Source: "required",
            State: "required",
            Postcode: "required",
        },
});


});

以下是验证和提交的其他表单的代码。

<form method="post" name="register-form" id="register-form" action="http://rpm.runway.com.au/actions/form/globalformaction.jsp" class="regform">
<div class="row firstrow">
<div class="col-md-12 titlecol">
    <h2 class="title formtitle">REGISTER NOW</h2>
<p class="desc">For exclusive updates on the launch of xyz please enter your details below</p>
<span class="close">X</span>
</div>
</div>
<div class="row secondrow">
    <div class="col-md-6 leftcol"><label class="lbl">first name*</label> <input type="text" id="FirstName" name="FirstName" class="reginput" /></div>
    <div class="col-md-6"><label class="lbl">last name*</label> <input type="text"  id="LastName" name="LastName"  class="reginput"/></div>
</div>
  <div class="row">
    <div class="col-md-6 leftcol"><label class="lbl">email* </label><input type="email" id="Email" name="Email"  class="reginput" /></div>
    <div class="col-md-6"><label class="lbl">phone* </label><input type="text" id="Mobile"  name="Mobile"  class="reginput" /></div>
    </div>
  <div class="row">
    <div class="col-md-6 leftcol"><label class="lbl">source of enquiry*</label>
    <select id="Answer0F1M413K11419D8M20081M8S3K5Q" name="Answer0F1M413K11419D8M20081M8S3K5Q">
    <option value="">Please select</option>
    <option>Online</option>
    <option>realesate.com.au </option>
    <option>Facebook / Social Media</option>
    <option>Signage</option>
    <option>Builder</option>
    <option>Newspaper</option>
    <option>Word of mouth</option>
    <option>Other</option>
    </select>
    </div>
    <div class="col-md-6"><label class="lbl">postcode* </label><input type="text" id="Postcode"  name="Postcode"  class="reginput" /></div>
 </div>
  <div class="row">
    <div class="col-md-12 colcomments"><label class="lbl">comments</label><textarea  class="reginput"></textarea></div>
  </div>
  <div class="row">
    <div class="col-md-12 submitcol"><input class="submit" type="submit" value="SUBMIT"></div>
    <a class="privacy" href="http://website.com/privacy-policy/" target="_blank">Privacy policy</a>
  </div>
</table>
<input type="hidden" name="GroupID" value="0T1C4S3A2Q5L22981L6O0O3H6U66">                                                                                                                                                                                                
<input type="hidden" name="NewContactStatusID" value="2f3c4880-dcd5-102c-8f29-644220d7d8b3">
<input type="hidden" name="Source" value="website">
<input type="hidden" name="NotificationTemplateID" value="0B1T3Q1C16743R0Z09472F1X430U">                                                                                                                                                                     
<input type="hidden" name="TemplateID" value="0Q1P423Y5U2V1W278A9U5W225493" >
<input type="hidden" name="LocationID" value="0Q1A4Q382D5222973O4J3T0F3F5T">   
<input type="hidden" name="-redirect"  value="http://website.com/registration-thanks/">   <!-- SET the value attribute dynamically to the URL of the page you want to redirect on submission of form     --> 
<input type="hidden" name="QuestionID" value="0F1M413K11419D8M20081M8S3K5Q" />

</form>

为什么只有FirstName在firstform上验证?

0 个答案:

没有答案