hi all
im adding rows to table by clicking add button.
These rows have fom elements in it.

It depends upon the user how many times he clicks the add button to add new row.

In the end all i want is to send the total number of rows added attached to a form.
Can anyone tell me how to do that.......

regards
ankur

Dani AI

Generated

Building on 's suggestion to track additions client‑side, the simplest reliable fix is: keep one named hidden input in the form and update its value whenever rows change instead of appending a new input every time. That prevents duplicates and guarantees the server receives a single, correct count.

Example pattern (concept only):

<input type="hidden" name="rowno" id="rowno" value="0" />

function addRow() {
  // create and insert table row...
  var count = myTable.tBodies[0].rows.length;
  document.getElementById('rowno').value = count;
}

Alternative: compute the count at submit time so you never need to update during every add/remove:

form.addEventListener('submit', function () {
  document.getElementById('rowno').value = myTable.tBodies[0].rows.length;
});

If for some reason you must create the input dynamically, check for an existing element by id and update or remove it before creating another. Common bugs to watch for: inserting elements with innerHTML += (can duplicate event handlers or produce unexpected nodes), forgetting to give the hidden input a name so the server can read it, and updating the value after the form has already started submitting. Use the browser console to inspect the form element just before submit to verify the rowno value.

If rows can be removed, either decrement a maintained counter correctly or (safer) always re-count DOM rows after each change. Avoid relying on multiple identical inputs to carry a single value; different servers/frameworks handle duplicate names differently.

Recommended Answers

All 2 Replies

JavaScript, set up variable which will be inceased by 1, every click of your button.

hi
the prob that im facing is ......

suppose the value of no. of rows is in variable 'rowno'

now im sending this to my server for processing by making text button n attaching that to table.
now on my server i retrieve the value from this text button........


now what is happening is that....
if the user add new row after the first.....then a new text field is created for him.
what i end up doin is that everytime user add new row i append a new text field.......im not able to remove the previous text field.....

Can antone help me with this.......

regards
ankur


when user add the rows for more than 1 times.....the text button is added

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.