0

Currently I have a table form I am using for submit. This is a small excerpt from the chunk of code I am working with.

<tr class="draggable even">
  <td class="choice-flag">
    <a title="Drag to re-order" href="#" class="tabledrag-handle">
      <div class="handle">&nbsp;</div>
    </a>
  </td>
  <td>
    <input name="recipe_ingredients[ing][1][ri_id]" data-thmr="thmr_141" type="hidden">
    <div class="form-item form-type-textfield form-item-recipe-ingredients-ing-1-quantity"     data-thmr="thmr_143">
      <label for="edit-recipe-ingredients-ing-1-quantity" data-thmr="thmr_144">Quantity</label>
      <input class="form-item-recipe-ingredients-quantity form-text" id="edit-recipe-ingredients-ing-1-quantity" name="recipe_ingredients[ing][1][quantity]" value="" size="8" maxlength="8" data-thmr="thmr_142" type="text">
    </div>
  </td>
  <td>
    <div class="form-item form-type-select form-item-recipe-ingredients-ing-1-unit-key" data-thmr="thmr_146">
      <label for="edit-recipe-ingredients-ing-1-unit-key" data-thmr="thmr_147">Unit</label>
      <select class="form-item-recipe-ingredients-unit-key form-select" id="edit-recipe-ingredients-ing-1-unit-key" name="recipe_ingredients[ing][1][unit_key]" data-thmr="thmr_145">

Now the problem is, each row has a unique 1, 2, 3, 4, 5 identifier in the name of certain attributes. When clicking a button, I want it to add the next row, which would need to change a name like

edit-recipe-ingredients-ing-1-unit-key   

to

edit-recipe-ingredients-ing-2-unit-key

Is there a way that I can select and change all attributes in an element that match a string and replace each of those occurrences with my new names? I plan to add new rows by using the jquery clone command.

Thank you for any help!

tomasbasham
  • 1,695
  • 2
  • 18
  • 37
chrisdottel
  • 1,053
  • 1
  • 12
  • 21

1 Answers1

0

You could clone your row, then change it inner HTML with RegExp.

But in fact you should have some kind of template here. Please, consider using Handlebars, or something like this.

Lesha Ogonkov
  • 1,218
  • 8
  • 20