Created
December 30, 2015 13:34
-
-
Save jitenbharadava/16f209cd17a45f179bbe to your computer and use it in GitHub Desktop.
Add Extra Field Like Google Plus.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTML PART : | |
<div class='extdiv'> | |
<input type="text" class="addmore" /> | |
</div> | |
JQUERY CODE : | |
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script> | |
<script> | |
$(document).on("keyup",".extdiv .addmore",function(){ | |
var dynamic = $(this).attr("class"); | |
var countoftext = $("."+dynamic).length; // count of entered value | |
var nextcount = $(this).parent(".extdiv").nextAll(".extdiv").length; // finding next class count | |
if(this.value.length >= 1 && nextcount == 0 ) // if length of textbox values greate than or equal to one and nextdiv class count is equal to zero | |
{ | |
$(this).after("<button>remove</button>"); // appending remove button to that field | |
var extrabox = "<div class='extdiv'><input type='text' class= 'addmore' /></div>" // creating required field | |
$(this).parent(".extdiv").after(extrabox); // appending | |
} | |
}); | |
$(document).on("click","button",function(){ | |
$(this).parent("div").remove(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment