I am beginner to UI designing and jquery. I am trying to increment the input name array index using jquery. I have an add button and clicking on it will add another row. But the name of the row should have name with incremented input array index value.
Here I require the paramKey[] and paramValue[] index value to increment as we click on an Add button.
Script I have written:
var i = 1;
$(document).ready(function() {
$(".addCF").click(function() {
i++;
$("#paramsFields").append('<tr valign="top"><th></th><td><input style="margin-left: 187px" type="text" class="code" id="paramFieldName" name="paramKey[i]" value=""/> <input type="text" class="code" id="paramFieldValue" name="paramValue[i]" value=""/> <a href="javascript:void(0);" class="remCF">Remove</a></td></tr>');
});
$("#paramsFields").on('click', '.remCF', function() {
$(this).parent().parent().remove();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="paramsFields">
<tr valign="top">
<td scope="row"><label for="paramFieldName">Params</label></td>
<td><input style="margin-left: 187px" type="text" class="code" id="paramFieldName" name="paramKey[0]" placeholder="Param Name" />
<input type="text" class="code" id="paramFieldValue" name="paramValue[0]" value="" placeholder="Param Value" />
<a href="javascript:void(0);" class="addCF">Add</a>
</td>
</tr>
</table>
Thanks in advance!!
var i=1;inside.ready()