views:

22

answers:

3
+1  Q: 

Jquery Validation

I have a bunch of rows in a form like this

                   <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>

every row has the same first part for the field name just different after the _ ... I need to say if either of the two check boxes are checked the isonotes for that row is required....

A: 

Take a look at this plugin:

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

You will probably need some custom validation to ensure that the required field is not blank when either of the checkboxes are checked.

$('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;
    }
js1568
A: 

You can do something like this:

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

I need to say if either of the two check boxes are checked the isonotes for that row is required....

You can do like this:

$('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;
     }
  }
});
Sarfraz
this did it perfectlythank you
David OBrien