[英]How to check at least one checkbox is checked from the array of checkboxes and the text area is not blank on checkbox with value “other” is checked?
I've following HTML code: 我正在遵循HTML代码:
<form name="question_issue_form" id="question_issue_form" action="question_issue.php">
<table class="trnsction_details" width="100%" cellpadding="5">
<tbody>
<tr>
<td></td>
<td>
<input type="checkbox" name = "que_issue[]" value = "Question is wrong" id ="chkQueWrong">Question is wrong</input>
</td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name = "que_issue[]" value = "Answers are wrong" id ="chkAnsWrong">Answers are wrong</input></td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name = "que_issue[]" value = "Question direction is incorrect" id ="chkDirIncorrect">Question direction is incorrecct</input></td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name = "que_issue[]" value = "Other" id ="chkOther">Other</input></td>
</tr>
<tr>
<td></td>
<td class="set_message" style="display:none;"><textarea name="que_issue_comment" rows="4" cols="25" maxlength="100"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Submit" id="report_question_issue"/></td>
</tr>
</tbody>
</table>
</form>
Now I need to check whether at least one checkbox is checked from the array of checkboxes and also only if the checkbox with value "Other" is checked then check whether the text area is filled or not. 现在,我需要检查是否从复选框数组中至少选中了一个复选框,并且也仅当选中值“ Other”的复选框时,才检查文本区域是否被填充。 If it's empty after checking the last checkbox then give error message. 如果在选中最后一个复选框后为空,则给出错误消息。 All these error messages should appear on form, no alert should be there. 所有这些错误消息都应出现在窗体上,没有任何警报。
something like this? 这样的东西?
var checkbox = document.getElementsByName("que_issue[]");
var checkedAtLeastOne = false;
$('input[type="checkbox"]').each(function () {
if ($(this).is(":checked")) {
//atleast one is checked
checkedAtLeastOne = true;
} else {
//error
document write bla bla bla
}
}
var other = document.getElementById("chkOther");
var textfield = document.getElementByName("que_issue_comment") if ($(other).is(":checked")) {
if ($(textfield).val().length == 0) {
//error
document write bla bla bla
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.