2010-08-26 65 views
1

我有一大堆的行像這樣jQuery驗證

    <tr> 
    <td nowrap><input type='checkbox' name='approve_DTC0F00EFAA43A8'</td> 
    <td nowrap><input type='checkbox' name='deny_DTC0F00EFAA43A8'</td> 
    <td nowrap><textarea name='isonotes_DTC0F00EFAA43A8'></textarea></td> 
    <td nowrap><input type='text' value='' name='secplan_DTC0F00EFAA43A8'></td> 
        </tr> 

每一行都有字段名相同的第一部分之後只是不同形式_ ... 我需要的,如果任一說兩個複選框被選中的isonotes該行需要....

回答

0

我必須說,如果任一兩個 複選框檢查isonotes 該行需要....

你可以這樣做:

$('form').submit(function(){ 
    if ($('input[name^="approve"]').is(':checked') || $('input[name^="deny"]').is(':checked')){ 
    if ($('textarea[name^="isonotes"]').val() === ''){ 
     alert('Required.....'); 
     return false; 
    } 
    else{ 
     return true; 
    } 
    } 
}); 
+0

這樣做很完美 謝謝 – 2010-08-26 19:51:46

0

在這個插件請看:

http://bassistance.de/jquery-plugins/jquery-plugin-validation/

你的Wi您可能需要一些自定義驗證來確保在選中任一複選框時必填字段不爲空。

$('tr').each(function() { 
    if (validRow(this)) 
    //okay 
    else 
    //not valid 
}); 
function validRow(this) { 
     if ($(this).find(':checked').size()) { 
      return ($(this).find('textarea:first').val() == ''); 
     } 
     return true; 
    } 
0

你可以做這樣的事情:

$("#myTable tr").each(function() { 
    if($(this).find(":checked").length && $(this).find("textarea").val() == "") { 
    alert("ISO Notes are required"); 
    } 
});