2010
09.01

I needed to validate two sets of selectboxes within a single form.  Each pair represented a minimum and a maximum. Here is the complete script http://muffinstump.ca/selectbox_validation.php.

The following is the jQuery set-up:

<script language="javascript" type="text/javascript">
 $(document).ready(function(){

  $('#tabs').tabs();
  $("#alert_AB, #alert_CD").dialog({
      buttons: {
        Ok: function() {
          $(this).dialog('close');
        }
      },
      autoOpen: false,
      show: 'blind',
      hide: 'explode'
    });

  $('#selectboxA, #selectboxB, #selectboxC, #selectboxD').change(function(){
      var start = $('#selectboxA').val();
      var end = $('#selectboxB').val();
      var from = parseInt($('#selectboxC').val());
      var to = parseInt($('#selectboxD').val());
      if( end > 0 && start > end ) {
        $('#alert_AB').dialog('open');
        $('#tabs').tabs("select", 1);
        $('#submit_button').hide();
        return false;
      } else if( to > 0 && from > to )
      {
        $('#alert_CD').dialog('open');
        $('#tabs').tabs("select", 2);
        $('#submit_button').hide();
        return false;
      } else
      {
        $('#submit_button').show();
      }
  });

 });
</script>

Comments are closed.