I have a pair of inputs. I have no problem with a user leaving the both of them blank. But what I need is a way to force the user to fill the second input field if he decides to fill the first input field and vice versa(or prevent form submission in the event of that).
Here are my input elements:
<input name="cas[]" id="ca">
<input name="exams[]" id="exam">
<button type="submit" id="submit">Submit</submit>
I would also appreciate if there is also an implementation for multiple input pairs.
2
Answers
You can create a custom
myXOR
function to check whether the two values are different:Then call it on the
change
event for either inputs, so the button is disabled if at any point only one input is filled in.A simple script like this should do the trick:
UPDATE:
For more than one pair if inputs give them a
class
name instead of (or as well as) anid
and then do this: