I have a form with two radio input. For one of these two radio input (type1) I display 2 input text. I would like before submiting the form to check if minimum one of these 2 input text boxes is not empty. But my script doesn't work.
HTML
<input id="type1" value="1" type="radio">
<input id="num1" value="" type="text">
<textarea id="numlist"></textarea>
<input id="type2" value="1" type="radio">
JQUERY
$('#form2').on('submit', function (e) {
if ($("input:radio[id=type1]").is(":checked")) {
var comment2 = $('#numliste').val();
var comment1 = $("#num1").val();
if ((comment1.length === 0) || (comment2.length === 0)) {
e.preventDefault();
alert('You have to write on minimum one input text');
return false;
}
}
});
'#numliste'should be'#numlist'nameattribute for both type1 and type2 to make them act like "radios"