Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am having 12 html controls on my page, in which 4 controls are optional which is a Group.


If user enters value in any of this 4 controls, he must need to enter other three field.

In-short, Either keep All 4 controls empty or Enter values in each of them.

What I have tried:

https://jsfiddle.net/ryleyb/cbJj6/

tried online tutorials but its not helping.
Posted
Comments
Karthik_Mahalingam 17-Jun-16 3:37am    
those 4 textbox alone you shall validate separately using js or jquery.
Sergey Alexandrovich Kryukov 17-Jun-16 4:04am    
Some thoughts:

Sometimes, I think that some libraries are designed to really help people to solve really complex problems without spending time for that. But some other libraries seem to be designed to keep morons from doing simple things in a stupid ways. They say: "forget all your ifs and loops; instead, learn our more specialized APIs and simply pass parameters to our functions". This approach creates a lot of limitations and cause people to learn many ad-hoc methods, but it creates an illusion that everything is done correctly, because the library is organized in a "correct" systematic and reliable way.

Come to think about, what can be simpler that some general-case validation? Take input data, implement all the rules in a way which fits the particular application field (after all, some ifs, some comparisons, and so on, nothing hard), decide how to show the problems in case of all failures, present the explanation of the problem is some HTML elements, and so on. But no! jQuery .validate sais that first parameter should be an object with rules, followed by groups, and so on.

So, here is my advice: use jQuery and other libraries where it is really convenient. But the most of the code should be JavaScript written from the first principles. After all, what is the purpose of high-level programming languages? Because they are universal. You learn main programming principles and the language that's it. You don't need the library to solve simple problems. Simple and natural programming should not be replaced by mechanical following rules of "smart" libraries, which also includes a lot of reading of documentation and even 'searching online tutorials". Are they written to create limitation and tedious procedures of following there rules? Are they the libraries for the sake of libraries?

Of course, your problem is quite simple and can be solved in different ways, including jQuery .validate. But why not using simple and natural process of JavaScript development instead?

—SA
[no name] 17-Jun-16 6:52am    
Yea, Developing logic using Javascript helped.
Sergey Alexandrovich Kryukov 17-Jun-16 9:20am    
Great. This is another victory of reason over dogmatism.
—SA
ZurdoDev 17-Jun-16 10:11am    
This is very easy. Where are you stuck?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900