I have an html form. An entry can be added multiple times with different values and is given a name as array (like fieldname[]). Clicking [+] button creates new fields with [-] button, on clicking will remove that entry.
<table cellpadding="0" cellspacing="0">
<tr>
<td>Item</td>
<td id="resource">
<input id="item" name="item[]" type="text" value="">
</td>
<td>
<img id="addScnt" alt="[+]"> </td>
</tr>
<br>
<button id="go">go</button>
</table>
jQuery(document).ready(function($){
var scntDiv = $('#resource');
var i = $('#resource p').size() + 1;
var name = $('#resource p');
$('#addScnt').live('click', function() {
$('<tr><td class="" id=""><input id="item" name="item[]" type="text" value=""><img id="remScnt" alt="[-]"></td></tr>').appendTo(scntDiv);
i++;
return false;
});
$('#remScnt').live('click', function() {
if( i > 1 ) {
$(this).parent().parent().remove();
i--;
}
return false;
});
});
Here is the fiddle
What I want is, when i click go button, an array should be created with input elements, starting with index 0 for the value of 1st entry. Also, rows should be given ids using the same value (0 for 1st row, 1 for 2nd etc..). I have defined some ids on CSS, and if the ids are assigned, it may change the color. The array may be alerted finally (I want to use that with ajax, to pass values one by one).
How can I do this?