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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:15:51+00:00 2026-05-19T02:15:51+00:00

I have 2 forms, namely (ids mentioned) ‘add_product’ and ‘edit_product’ Now I am using

  • 0

I have 2 forms, namely (ids mentioned) ‘add_product’ and ‘edit_product’

Now I am using jQuery validation plug-in, both the forms have same validation (similar to mentioned in following example)

jQuery("#add_product").validate({
    rules: {
        name:"required",
        price:"number"
    },
    messages: {
        name:"Please enter Plan Name",
        price:"Enter a valid number"
    }

});

and

jQuery("#edit_product").validate({
    rules: {
        name:"required",
        price:"number"
    },
    messages: {
        name:"Please enter Plan Name",
        price:"Enter a valid number"
    }

});

I want to combine them into 1 rule/function, how can I achieve this?

Thanks

  • 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-19T02:15:52+00:00Added an answer on May 19, 2026 at 2:15 am

    Store the options in a variable and reuse it.

    var vProduct = {
        rules: {
            name:"required",
            price:"number"
        },
        messages: {
            name:"Please enter Plan Name",
            price:"Enter a valid number"
        }
    };
    
    jQuery("#add_product").validate(vProduct);
    jQuery("#edit_product").validate(vProduct);
    

    Unfortunately you can’t simply use jQuery("#add_product, #edit_product").validate({...}) because the plugin doesn’t handle more than one element being selected.

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

Sidebar

Related Questions

I have 3 tables namely users, items and purchase. Purchase hasMany('Users') and hasMany('Item'). Now
Is it possible to have a variable number of fields using django forms? The
I have a Windows Forms application developed using C# in .NET framework 3.5, Service
I have forms which work fine. I have a quiz which works fine. When
In a typical business application it is quite common to have forms that are
I have multiple forms for lots of products on my page and want to
I have Windows Forms UI, that allows me to enter format for string formatting
I have two forms in my project, form1 and form2. I have added a
I have several forms added to the pages of the tab control via tabcontrol.tabpages.controls.add
I have two forms, and so two different submit buttons, for one page (page

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.