Add and Remove Text Box
<html>
<head><script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script></head>
<div class="wrap">
<button class="skill_button">Add More Fields</button>
<div><input type="text" name="skills[]" id="skills"><a href="#" class="remove_skill">Remove</a></div>
</div>
<script>
jQuery(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".wrap"); //Fields wrapper
var add_button = $(".skill_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div><input type="text" name="skills[]"/><a href="#" class="remove_skill">Remove</a></div>'); //add input box
}
});
$(wrapper).on("click",".remove_skill", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
</script>
</html>
<head><script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script></head>
<div class="wrap">
<button class="skill_button">Add More Fields</button>
<div><input type="text" name="skills[]" id="skills"><a href="#" class="remove_skill">Remove</a></div>
</div>
<script>
jQuery(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".wrap"); //Fields wrapper
var add_button = $(".skill_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div><input type="text" name="skills[]"/><a href="#" class="remove_skill">Remove</a></div>'); //add input box
}
});
$(wrapper).on("click",".remove_skill", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
</script>
</html>
Comments
Post a Comment