php - jQuery max value of fields and min in form -
i'm little bit new jquery have questions:
i have form 2 links can add 1 field , remove 1 field.
but problem want stop @ 10 fields, max can add 10 fields?
the second problem how can stop @ minimum 1 field, right it's deleting every field 0 if click remove time?
last question how can do, when press submit button, want remember how many fields on before pressed submit?
i hope can me, it's need quick :-d
jquery:
var = $('input').size() + 1; max = 10; $('#add').click(function() { $('<div><input type="text" class="field" name="dynamic[]" value="some text..." /></div>').fadein('slow').appendto('.inputs'); i++; }); $('#remove').click(function() { if(i > 1) { $('.field:last').remove(); i--; } });
html:
<a href="#" id="add">add +1</a> | <a href="#" id="remove">remove -1</a> <form method="post"> <div class="inputs"> <div> <input type="text" name="dynamic[]" class="field" value="some text..."/></div> </div> <input name="submit" type="submit" class="submit" value="submit"/> </form>
you can use $('.field').length
amount of elements class 'field'(a more specific class name helps here). if use class exclusively inputs can use solid count.
if ($('.field').length <= 10) { //add new 1 } else { //already 10 }
Comments
Post a Comment