验证链式选择

时间:2011-03-16 15:34:53

标签: jquery validation

我有一个这样的表格: -

 <table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><div id="subjectList1">
      <select name="language[]" class="required" id="f61">
        <option value="" selected="selected">-</option>
        <option>English</option>
        <option>Malay</option>
        <option>Mandarin</option>
        <option>Tamil</option>
        <option>Arabic</option>
      </select>
    </div></td>
    <td>&nbsp;</td>
    <td><select name="spoken[]" class="required">
      <option value="" selected="selected">-</option>
      <option value="Spoken">Spoken</option>
      <option value="Written">Written</option>
      <option value="Spoken and written">Spoken and written</option>
    </select></td>
    <td>&nbsp;</td>
    <td><select name="fluency[]" class="required">
      <option value="" selected="selected">-</option>
      <option value="Basic">Basic</option>
      <option value="Average">Average</option>
      <option value="Fluent">Fluent</option>
      <option value="Mother tongue">Mother tongue</option>
    </select></td>
    <td>&nbsp;</td>
    <td><input type="checkbox" value="other" id="showOther1" /></td>
    <td>&nbsp;</td>
    <td>Others</td>
    <td>&nbsp;</td>
    <td><div id="otherLanguegeReq1"><input type="text" id="language1" style="display:none;" class="required" /></div></td>
  </tr>
</table>
  <br />

我可以验证下拉菜单 - “口语[]”&amp; dropdown-“fluency []”当语言[]的值不为空时?

对此有何看法?

感谢提前

1 个答案:

答案 0 :(得分:0)

您当然可以调用类似下面提交的内容或者想要验证它。在每个函数中,您可以构建一个消息或.addClass(“不完整”),以便在视觉上设置所需元素的样式。


function ValidateInputs() {
  var complete = true;
  if($("#f61 option:selected") != ""){

    $(".required").each(function() {
      if ($(this).val().length == 0) {
        complete = false;
      }
    });

    if (!complete) {
      alert("Please ensure that you have completed all required fields.");
    }

  }
  return complete;
}