I have a dynamic form that I add several fields and I create together a div that is passed by a button that is assigned a onClick
event for it passing a function that receives a parameter. This parameter is a sequential number that I create through a foreach
with an array of the DB. But when I click on adding another field, this parameter of the function remains the same, not incrementing. I wanted to be able to increment the value of the parameter, but I do not know how to do this via Jquey.
<?php
$contador = '';
foreach ($programas as $key => $formu)
{
$contador += 1;
?>
<div id="campos_<?php echo $contador; ?>" name="campos[]" class="campos col-md-12" >
<br><div class="btn btn-primary" id="rmv_<?php echo $contador; ?>" onclick="remover('campos_<?php echo $contador; ?>')"><span class="fa fa-minus"></span></div>
</div>
Notice that I want to increment this:
onclick="remover('campos_<?php echo $contador; ?>')"
I can increment the id counters through jquery like this:
campos.children().find("#rmv_"+(contador)).attr('id','rmv_'+(comentario+1));
but I have no idea how to change this parameter value.
Can anyone who has gone through this help me?