简体   繁体   English

如何从复选框数组中检查至少一个复选框,并且复选框中的文本区域不为空白,且其值为“ other”?

[英]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.

相关问题 如何检查复选框列表中是否至少选中了一个复选框,其名称属性为数组 - How to check if at least one checkbox is checked from list of checkboxes with it name attribute as array 如何检查多个复选框中是否选中了至少一个复选框? - How to check that at least one checkbox is checked in multiple checkboxes? 如何检查用户是否已使用jQuery / Javascript选中了一组复选框中的至少一个复选框? - How to check whether user has checked at least one checkbox from a group of checkboxes using jQuery/Javascript? 选中一个复选框后如何删除其他复选框上的复选框 - how to remove check on other checkboxes when one checkbox is checked 检查是否至少选中了一个复选框 - Check if at least one checkbox is checked 如何检查表单中是否至少选中了一个复选框? - How to check if at least one checkbox is checked in the form? 如何验证在每组复选框中至少选中了一个复选框 - How to validate that at least one checkbox is checked in each set of checkboxes 检查是否至少使用 jQuery 选中了一个复选框 - Check if at least one checkbox is checked using jQuery 选中至少一个复选框,选中jquery验证 - check at least one checkbox checked jquery Validate 当未选中组中的复选框或至少选中一个复选框,然后为相关的div添加一个类时,如何捕获事件? - How to catch the event when none of checkboxes from group is checked or at least one checkbox is checked and then add a class for the related div?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM