cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <form id="myform" action="#">
  
 <p>
   <label for='fullname'> Name:</label><input type='text' name='fullname' /></p><p>
  <label for='email'> Email:</label><input type='text' name='email' />   
  </p>
  <h3>Items </h3>
  <table border="0"  id="items_table">
  <tr>
  <td>Item</td>
  <td>Quantity</td>
  <td> </td>
  </tr>
    <tr id='master_tr'>
    <td>
    <select name='item' class='itemsel' size='1'>
      <option value=''>Select ...</option>
        <option value='Avocado'>Avocado</option>
        <option value='Bell Pepper'>Bell Pepper</option> 
      <option value='Bitter Melon'>Bitter Melon</option> 
      <option value='Chayote'>Chayote</option>
        <option value='Cucumber'>Cucumber</option>
      <option value='Ivy'>Ivy</option> Gourd
        <option value='Aubergine'>Aubergine</option>
      <option value='Olive'>Olive</option> fruit
      <option value='Luffa'>Luffa</option>
      </select>
  </td>
  <td><input type="text" name="qty" class='itemqty' ></td>
  <td><a href='javascript:void(0);' id="addbutton">Add</a> | <a href='javascript:void(0);' id="removebutton">Remove</a></td>
  </tr>
  </table>
  <input type="submit" name="submit" value="Submit">
</form>
            
          
!
            
              body
{
  font-family: Arial, Sans-serif;
  font-size:0.8em;
}
.error
{
color:red;
font-family:verdana, Helvetica;
}
            
          
!
            
              
$(function()
  {
    var n_item=1;
    $('#addbutton').click(function()
    {
      var $trcopy = $('#items_table tr#master_tr').clone(true);
      $trcopy.attr('id','');
      n_item++;
      $('.itemsel',$trcopy).attr('name','item'+n_item);
      $('.itemqty',$trcopy).attr('name','qty'+n_item);      
      $('#removebutton',$trcopy).show();
      
      $('#items_table').append($trcopy);
      //Need to add the element to the form first (see the append above)
      //Then call the rules() function
      $('.itemsel',$trcopy).rules('add',
                {
                  required:true,
                  messages:
                  {
                     required:"Please select item"
                   }
                 });
      
      $('.itemqty',$trcopy).rules('add', 
                 {
                    required:true,
                    min:1,
                    max:5,
                    messages:
                    {
                      required:"Please enter quantity",
                      min:"minimum quantity {0}",
                      max:"max quantity {0}"
                    }
                  });
      
    });
    $('#removebutton').click(function()
    {
      var $tr = $(this).parents('tr');  
      $tr.remove();
    })
    
    $('#items_table tr#master_tr #removebutton').hide();
    
    $('#myform').validate(
      { 
      rules:
        { 
          fullname:{ required:true },
          email:{required:true},
          'qty':{required:true}
        },
        errorPlacement: function(error, element) 
        {
            if ( element.parents("#items_table").length > 0 ) 
            {
              var $errbox = element.parents('tr').next('tr.error');
              var errortxt = error.text();
              if($errbox.length > 0)
              {
                if(errortxt==='')
                {
                  $errbox.remove();
                }
                else
                {
                  $('td',$errbox).text(errortxt);
                }
              }
              else
              {
                element.parents('tr').after("<tr class='error'><td colspan='3'>"+error.text()+"</td></tr>");
              }
            }
            else 
            { 
                error.insertAfter( element );
            }
        }, 
        success: function (label, element) 
        {
          
          if ( $(element).parents("#items_table").length > 0 ) 
          {
            var $errbox = $(element).parents('tr').next('tr.error');
            $errbox.remove();
            $(element).removeClass('error');
          }
        }
      });
    
  });
            
          
!
999px
Loading ..................

Console