My Validation Code is like this :
$('#myForm').submit(function() {
if ($("li.msg").length && $("li.msg ol li").length) {
alert('success');
return false;
}
else if (!$("li.msg").length && !$("li.msg ol li").length) {
alert('You do not add a room type');
return false;
}
else {
alert('Please drop customer to a room type');
return false;
}
});
});
Here is an example of the HTML that is not working correctly:
<form id="myForm" action="" method="POST">
box 2 (Room Type)
<br>
<select id="room_type">
<option value="1">Single Room</option>
<option value="2">Double Room</option>
<option value="3">Twin Room</option>
</select>
<input type="button" value="Add" style="margin-top: -10px;" id="add_room">
<ol class="example areaDROP vertical" id="room_list">
<li class="room_number msg" data-id="1" data-name="Single Room">
Single Room
<ol>
<li class="">Lionel Messi</li>
</ol>
</li>
<li class="room_number msg" data-id="1" data-name="Single Room">
Single Room
<ol>
</ol>
</li>
</ol>
<button type="submit">Save</button>
</form>
Demo & Complete Code is like this : https://jsfiddle.net/oscar11/mL7qr5z1/
My validation is working in some cases, but in certain cases like the form above, it is showing success when it should be showing, "Please drop customer to a room type".
Any suggestions to solve this problem?
Thank you