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 892077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:59:37+00:00 2026-05-15T13:59:37+00:00

I m using jquery validator plugin. i need to validate some field with some

  • 0

I m using jquery validator plugin. i need to validate some field with some condition. how do we apply that?

i have a form where user select a country..then user creates branch on the fly,
now i want to validate that if user do not select a county then prompt to select country and if user select a country then prompt to create atleast one branch.

what i do as far

if user create any branch then there is a hidden field of counting branch. but that field is filled after creating branch, before that( on page load ) is has no value so if i validate for that hidden field then it always return true. what should i do

here is code snippet i have used but i know there must be a better way to manipulate all above..please suggest me optimize way to do this

<script type="text/javascript">
jQuery.metadata.setType("attr", "validate");

jQuery('#createForm').submit(function(){
        if(jQuery("#hasbranch").val()== 0 ){
            jQuery(".brancherror").html('Atleast one branch is necessary');
            return false;
        }
    });

var validator=jQuery("#createForm").validate({
               rules: { list of rules},
               messgae : { list of messages },                                
});
</script>

<form name="createForm" id="createForm">
<table>
<tr>
      <td>Select Country :</td>
      <td >
      <select name="country_id" id="country"  class="selectbox" onchange="return showBranch();"     title="Please select country" validate="required:true"  >
    <option value="" >Select Country </option>
    <?php foreach($this->country as $key => $country) { ?>
    <option value="<?php echo $country->id; ?>"<?php if ($country->id == $this->ad_data['country_id']) {?> selected="selected" <?php } ?> > <?php echo $country->name; ?></option> 
    <?php } // end of foreach ?>
      </select>
      </td>
  </tr>
  <tr>
      <td> //Here is link to add branch (via iframe) </td>
  </tr>    
  </table>
   <input type="hidden" value="<?php echo count($_SESSION['branches'])? 1: 0 ;?> name="hasbranch" id="hasbranch" />
   </form>  
  • 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-15T13:59:38+00:00Added an answer on May 15, 2026 at 1:59 pm

    You could use depends on rule to apply a conditional validation:

    rules: {
        someField: {
           required: true,
           email: {
               depends: function(element) {
                   // require someField to be a valid email only if the user checked 
                   // to be contacted by email
                   return $("#contactform_email:checked");
               }
           }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to validate a textarea using the plugin jQuery Validate, to do that
I'm using jQuery validate plugin. I have 3 fields, and need to validate them
I have a form that validates using the jQuery plugin: Validation, v1.9.0. The validation
I'm using the jQuery validation plugin found here: http://plugins.jquery.com/project/validate In my form I have
I'm using jQuery Validate for a form. I need to add some functionality so
I'm trying to validate a php register form using valid8 jquery plugin. i need
I have a form that uses the validation plugin, but I need to validate
I am using jquery validation plugin for form validation. I have added a custom
I'm try to validate form using jquery validation plugin my from code: source code
I'm using the Jquery Validation plugin to validate my form on the client before

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.