Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6914051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:17:53+00:00 2026-05-27T09:17:53+00:00

validate for my Form, I’ve included a snippet of the html and coding. For

  • 0

validate for my Form, I’ve included a snippet of the html and coding. For my Profile Type I use a show/hide piece of coding to display another div if value 2 is selected in Profile Type. What I need to happen here is for the jquery.validate to only validate div id="pro2"‘s form elements IF its shown, and if not then don’t show an error for it not being complete.

Questions is how do I do this?

<script type="text/javascript">
$(document).ready(function() {
    function showDiv(element, pro2) {
        if (pro2.children("option:selected").val() == 2) element.show();
        else element.hide();
    }
    var myElement = $("div#pro2");
    var mypro2 = $("select#ptype");
    $("select").change(function() {
        showDiv(myElement, mypro2)
    });
    $("#ctry").change(function() {
      $(".state").hide();
      var stateSelect = $("#state_" + $(this).val());
      stateSelect.show();      
    });
    $("input[data-code]").each(function() {
      $(this).autocomplete("/js/zip/" + $(this).data("code") + ".php", {
      matchContains: true, matchFirst: true, mustMatch: false,
      selectFirst: false, cacheLength: 10, minChars: 1, autofill: false,
      scrollHeight: 150, width: 180, max: 20, scroll: true
      });
    });
    $("#form1").validate({
        errorLabelContainer: $("#form1 div.error")
    });     
   // $("#reg_form").validate();    
});
</script>

HTML Code:

<div class="error"></div>    
<label>Profile Type:</label>
          <select name="add[type]" id="ptype" 
          title="Select Profile Type!" class="{validate:{required:true}}">
            <option value="">-- Select</option>
            <option value="2">(MF/FF/MM)</option>
            <option value="1">F or M</option>
          </select>


    <div id="pro1">        
            <label>First Name:</label> 
            <input type="text" name="add[name]" size="20" maxlength="15" id="fname" 
            title="Your First Name" class="{required:true,minlength:1}"/>
            <span class="rsmall">internal use not displayed</span><br />
    </div>
    <div id="pro2">
            <label>First Name:</label>
            <input type="text" name="cpl[name]" size="20" maxlength="15" id="fname" 
            title="Your First Name" class="{required:true,minlength:1}"/>
            <span class="rsmall">internal use not displayed</span><br />
    </div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:17:53+00:00Added an answer on May 27, 2026 at 9:17 am

    Actually this should work. jquery.validate ignores all hidden fields by default (if you want to customize this behavior, it has an option “ignore” which is set to “:hidden” by default).

    Ther are two odd things in your code, your input fields use the same id “fname”, and instead of class="{required:true,minlength:1}" it should be class="required" minlength="1". At least in the jquery.validate plugin I am using. Maybe you are using a different plugin or older version?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my ViewModels I use several DataAnnotations to validate the form data, there are
I have a form that I want to validate looks like this: <!DOCTYPE html
I want to validate form fields when submitting the form, I use isset() to
I am trying to use IValidatableObject to validate form values with respect to each
I'm using RSV to validate form element, and tinymce to convert textarea to editor.
How do I change validates_numericality_of :test, :greater_than_or_equal_to=>0 into validate form I tried only character
I am currently trying to validate a form server side, the way it works
Hey there, I'm trying to validate a form with Zend_Validate and Zend_Form. My element:
Im using asp.net webforms. c# I want to validate a form. In the codebehind
I'm using jQuery validate on a form I am building and it is working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.