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.

  1. but problem want stop @ 10 fields, max can add 10 fields?

  2. the second problem how can stop @ minimum 1 field, right it's deleting every field 0 if click remove time?

  3. 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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -