two things:
First, that's javascript - client side validation. It's open to tampering by the user as much as with firebug, etc.
Javascript is great for usability: it makes things more convenient. JS validation warns if they're trying to do something that won't work. But if they're trying to do something "bad," JS is useless to prevent it. That's why I mentioned server-side validation.
Second, w3schools.
You'll need to define the acceptable values and combinations (the exact approach will depend on what values are acceptable and how complex the combinations get), and then check that the user's selections work.
From your OP, it seems you simply have all of the animals categorized. So, your validation might look something like this (oversimplified, of course):
// define categories with acceptable values
$dog_categories = array(
'small_dogs' => array(
'terriers'
,'chihuahuas'
,'toy poodles'
)
,'big_dogs' => array(
'golden retriever'
,'great dane'
,'mastiff'
)
);
// get user input from form
$dog1 = $_POST['dog1'];
$dog2 = $_POST['dog2'];
// #1 SECURITY RULE:
// always assume the user input is wrong!
$same_category = FALSE;
// loop through the categories
foreach($dog_categories as $category){
// check if _both_ user values are present in the same category
if(in_array($dog1,$category) && in_array($dog2,$category)){
// if they are, then the user input is good
$same_category = TRUE; break;
}
}
// if the user input was good, continue
if($same_category === TRUE){ print "Good choice."; }
// if not, refuse the user input
else{ print 'quit messing with my form'; }