title: How to create dynamic row of table using Struts 1.3 and javascript
body: <p>I have a contact table, this table contains a first name, a last name, and multiple phone numbers. So my model is something like</p>
  
  <pre>
  <code>
  
      Contact {
      String firstName;
      String lastName;
      List phones;
      }
  
      Phone {
      String category; //home, work, mobile, etc
      String phoneNumber;
      }
  
  </code>
  </pre>
  
  <p>So it will have web page contains two input text for first name and last name, and an add phone button. When add button is clicked, it will generate two input text again for category and phone number, and an delete button to that row.</p>
  
  <p>I have tried using indexed=true, it will generate an html like</p>
  
  <pre><code>&lt;input type="text" name="phone[0].category" ... /&gt;
  &lt;input type="text" name="phone[0].phoneNumber" ... /&gt;
  </code></pre>
  
  <p>The problem is, i dont know how to write the javascript, because i dont know what is current index if user click add button, how about if user have clicked delete button and then add button, what index it will be? It is ok if i have missing index? Something like</p>
  
  <pre><code>&lt;input type="text" name="phone[0].category" ... /&gt;
  &lt;input type="text" name="phone[0].phoneNumber" ... /&gt;
  &lt;input type="text" name="phone[3].category" ... /&gt;
  &lt;input type="text" name="phone[3].phoneNumber" ... /&gt;
  </code></pre>
  
  <p>Note: please consider for the edit scenario too.</p>