kapustnik,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.add').click(function(){
var num = parseInt($('.counter').val())+1;
if(num < 5) {
$('.counter').val(num);
$('<div class="dynamic_'+num+'"><input type="input" name="dynamic_input_'+num+'" value="" /> <a href="#" rel="'+num+'" class="dynamic_remove">-</a></div>').appendTo('.overflow_dynamic');
}
else {
alert(num);
}
return false;
});
$('div').on('click','.dynamic_remove',function(){
var num = $(this).attr('rel');
$('.dynamic_'+num).remove();
num = parseInt($('.counter').val())-1
$('.counter').val(num)
return false;
});
});
</script>
</head>
<body>
<div class="overflow_dynamic">
<input name="counter" class="counter" value="0" />
</div>
<input name="" class="add" type="button" value="add">
</body>
</html>