felix001 felix001 - 11 months ago 73
HTML Question

Add/Remove Inputs from Jquery Array in HTM Form

I need to add and remove inputs from a form. And then add remove the input values from an array that I can eventually POST.

The input additions and removes are fine. But I cannot get the array to print the new values(?)


<div id="p_scents">
<label for="p_scnts"><input type="text" id="p_scnt" size="20" name="p_scnt" value="" placeholder="NETWORK/[IP/CIDR]" /></label><a href="#" id="addScnt">Add Another Input Box</a>
<p class="result"></p>


$(function() {
var scntDiv = $('#p_scents');
var i = $('#p_scents p').size() + 1;
var encdom_local = ['something'];

$('#addScnt').live('click', function() {
$('<p><label for="p_scnts"><input type="text" id="p_scnt" name="p_scnt_' + i +'" value="" placeholder="NETWORK/[IP/CIDR]" /></label> <a href="#" id="remScnt">Remove</a></p>').appendTo(scntDiv);
return false;
$('#remScnt').live('click', function() {
if( i > 2 ) {
return false;


Answer Source

If what you mean by print is this line of your code:


Then it 'happens' only once, after you add your event listeners. If u want to print it everytime, just add this printing method to the .live() events.