$("form#zzz input[type='button']").on("click", function(){
$(this).parent().submit();
});
$("form#test").on("submit", function(){
if($(this).children("textarea, input[type='text']").val() == "")
alert("You need to feel up all fields.")
else
alert("OK");
});
<div id="comment">
<h2>Some comment</h2>
<form id="test" onsubmit="return false">
Name: <br/>
<input type="text"/> <br/>
Comment: <br/>
<textarea rows="5" cols="30" name="comment"></textarea> <br/>
<input type="button" value="Send"/>
</form>
</div>
/////////////
Well, the problem is that if() doesn't want to work as it has to:
if($(this).children("textarea, input[type='text']").val() == "")
Here is simple check if(two fields empty) or not.
It can be checked separately. But, if I wanna check 2 of them at the same time - somehow if() checks only is input(type=text) filled up or not. If input(type=text) is filled up - it's going to alert OK. And it doesn't care about <textarea> at all. So if I will write something in <input> and will not write anything in <textarea> - it will alert OK.
And there is no difference in order of writing them in children:
if($(this).children("
textarea
,
input[type='text']
").val() == "")
or
if($(this).children("
input[type='text']
,
textarea
").val() == "")
What am I doing wrong?