
    
 $(function() { // when document has loaded  
 

   var i = $('.certyear').size() + 1; // check how many input exists on the document and add 1 for the add command to work  
   


   
  $('a#addcert').click(function() { // when you click the add link  
	  var currentyear = new Date().getFullYear();
	   var r=2001;
	  var option = '<select class=certyear  name="certyear['+ i +']" id="certyear['+ i +']" class="" ><option value="" SELECTED>Wybierz Rok</option>';
	   while (r<=currentyear) {
	   option +='<option value="'+r+'">'+r+'</option>';      
	   r++;
	   }
	   option += '</select>';
	  
        $('<p><label>W którym roku otrzymano certyfikat?</label> '+option+' </p><p>Nazwa certyfikatu <input type=radio name=certname[' + i + '] value="LCAE">LaCAE <input type=radio name=certname['+ i +'] value="ZF">ZF</p>').appendTo('#cert'); // append (add) a new input to the document.  
 // if you have the input inside a form, change body to form in the appendTo  
        i++; //after the click i will be i = 3 if you click again i will be i = 4  
     });  
  
    $('a#remove').click(function() { // similar to the previous, when you click remove link  
   if(i > 1) { // if you have at least 1 input on the form  
        $('input:last').remove(); //remove the last input  
         i--; //deduct 1 from i so if i = 3, after i--, i will be i = 2  
    }  
     });  
   
 });  
  
