Answer the question
In order to leave comments, you need to log in
How to make mandatory one input out of two available?
There is a callback form for contacting a client with 3 fields: name, phone number, email. How to make the validation pass only if one of the contact fields (phone or email) is filled.
Filled in the field "Name" and "Phone" - validation passed.
"Name" and "Email" - validation passed.
Filled only "Name" - validation failed.
codepen.io/anon/pen/epLYbr
Answer the question
In order to leave comments, you need to log in
All of the above is good, but it was relevant before HTML5. HTML5 has a validation api, and everything else is crutches. jsfiddle.net/ufma1kj4
jqueryvalidation.org/require_from_group-method
Download this plugin, and be sure to download additional-methods.js to it on the download page
I sent you the docks, your user case is clearly there.
jsfiddle.net/Ivanq/2ac8gc38
See for yourself - when there is no data, the page is not refreshed.
This is the direction in which direction to dig
$('form').on('submit', function(e){
var em = $("#email").val();
var ph = $("#phone").val();
if ((em == '') && (ph == '')){
alert('error');
e.preventDefault();
} else {
alert('done')
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question