Hi All,
I am trying to create html form which looks like Excel Sheet.
I am able to some extent, only thing where I am stuck is how to make the rows dynamic(Once the user click Enter a new row should Enter automatically).

Frnds can U please help me here.

Please help me as it is urgent.


Thanks in advance.
Manish

Dani AI

Generated

Short diagnosis and a simple fix for the behavior reported by : when a cloned table row keeps the previous row's entries, the cloning method is copying the form-control state. Common causes are using cloneNode(true) or copying innerHTML (both can carry current values or value attributes), duplicated id attributes on inputs, or browser autofill. was right to warn about intercepting Enter — that key normally submits a form — so the approach should prevent default submission and be clearly signalled in the UI.

Two reliable patterns

  1. Keep a hidden, empty template row in the DOM and clone that when a new row is needed. The template has blank inputs and no IDs, so clones start clean.
  2. If cloning an existing row, immediately clear the form controls on the clone (and remove duplicate IDs). Example clearing logic:
var newRow = existingRow.cloneNode(true);
var controls = newRow.querySelectorAll('input, textarea, select');
for (var i = 0; i < controls.length; i++) {
  var c = controls[i];
  if (c.tagName === 'SELECT') c.selectedIndex = 0;
  else if (c.type === 'checkbox' || c.type === 'radio') c.checked = false;
  else c.value = '';
  if (c.id) c.removeAttribute('id');
}
table.tBodies[0].appendChild(newRow);

Capturing Enter without submitting

Use a keydown handler with preventDefault, and prefer event delegation so newly added rows don’t need per-row bindings:

table.addEventListener('keydown', function(e) {
  if (e.key === 'Enter' || e.keyCode === 13) {
    e.preventDefault(); // stop form submit
    var row = e.target.closest('tr');
    addBlankRowAfter(row); // implement via template or clone+clear
  }
});

Practical tips and cautions

  • Remove or regenerate duplicated id attributes after cloning.
  • To avoid browser autofill filling the template, use autocomplete="off" on the form/inputs.
  • Prefer a visible “Add row” control or document the Enter behavior so users aren’t surprised (echoes ’s UX point).
  • Use delegation for other event handlers (keypress/validation) so cloned rows inherit behavior without rebinding.

This approach gives a clean blank row every time and avoids accidental form submissions or duplicate element IDs.

Recommended Answers

All 6 Replies

hi,
I have seen the code but my requirement is totally different.
I am trying to make a form which looks and work like the Excel sheet.
I am stuck at this point...
When a user hit the Enter button a new row should generated(Dynamically).

Thanks in advance

Manish

This is the code....
<html>

<head>
<title>Repository</title>
</head>
<body>

<center><h9>Repository</h9></center>

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="1291" id="AutoNumber1" height="63">
<tr>
<td width="30" bgcolor=#94B6FF align="center" height="70">
<font face="verdana" color=white style="font-size: 8pt">Si-no</font></td>
<td width="36" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">
Ticket Number</font></td>
<td width="54" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Description</font></td>
<td width="37" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Priority</font></td>
<td width="70" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">
Understandings</font></td>
<td width="37" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Planned
Start Date</font></td>
<td width="30" bgcolor=#94B6FF align="center" height="70">
<font style="font-size: 8pt" color="white">Actual</font>
<font color=white style="font-size: 8pt"> start
Date</font></td>
<td width="44" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">RFF Approval
Date</font></td>
<td width="37" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Planned End
Date</font></td>
<td width="40" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Actual End
(Date Delivery Date)</font></td>
<td width="37" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Project
Delayed Days)</font></td>
<td width="44" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Planned Date
for Customer Signoff</font></td>
<td width="44" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Received
Customer Sign-off</font></td>
<td width="27" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Status</font></td>
<td width="122" bgcolor=#94B6FF align="center" height="70">
<p align="center"><font color=white style="font-size: 8pt">Stage
(Local|Staging|Production)</font></p>

</td>
<td width="45" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Assigned</font><font style="font-size: 8pt">
</font><font color=white style="font-size: 8pt">Resources</font></td>
<td width="37" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Planned</font><font style="font-size: 8pt">
</font><font color=white style="font-size: 8pt">Dev</font><font style="font-size: 8pt"> </font>
<font color=white style="font-size: 8pt">Efforts</font></td>
<td width="33" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Actual</font><font style="font-size: 8pt">
</font><font color=white style="font-size: 8pt">Dev</font><font style="font-size: 8pt"> </font>
<font color=white style="font-size: 8pt">Efforts</font><font style="font-size: 8pt"> </font><font color=white style="font-size: 8pt">(Billed</font><font style="font-size: 8pt">
</font><font color=white style="font-size: 8pt">Hours)</font><font style="font-size: 8pt"></font></td>
<td width="44" bgcolor=#94B6FF align="center" height="70">
<font color=white style="font-size: 8pt">Dev</font><font style="font-size: 8pt">
</font><font color=white style="font-size: 8pt">Effort</font><font style="font-size: 8pt">
</font><font color=white style="font-size: 8pt">(Variance Hours)</font><font style="font-size: 8pt"></font></td>

<td width="45" bgcolor=#94B6FF align="center" height="70">
<font style="font-size: 8pt">&nbsp;</font><font color=white style="font-size: 8pt"> % Complete
</font>
</td>

<td width="120" bgcolor=#94B6FF align="center" height="70" colspan="5">
<font color=white style="font-size: 8pt">Development Testing</font>
<p>&nbsp;</p>
</td>
<td width="132" bgcolor=#94B6FF align="center" height="70" colspan="5">
<font style="font-size: 8pt" color="white">&nbsp;&nbsp;&nbsp;&nbsp; QA
Testing</font>
<p>&nbsp;</p>
</td>
<td width="120" bgcolor=#94B6FF align="center" height="70" colspan="5">
<font color=white style="font-size: 8pt">Customer Acceptance Testing</font>
<p>&nbsp;</p>
</td>
<td width="120" bgcolor=#94B6FF align="center" height="70" colspan="5">
<font color=white style="font-size: 8pt">Comments</font>
<p>&nbsp;</p>
</td>


</tr>
<tr>
<td width="30" bgcolor=#94B6FF align="center" height="41">

<!--<td width="30" height="18">&nbsp;adad</td>-->
<td wwidth="30" bgcolor=#94B6FF align="center" height="1" width="36">&nbsp;</td>
<td width="54" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="37" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="70" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="37" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="30" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="44" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="37" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="40" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="37" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="44" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="44" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="27" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="122" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="45" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="37" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="33" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="44" bgcolor=#94B6FF align="center" height="1">&nbsp;</td>
<td width="45" bgcolor=#94B6FF align="center" height="1"></td>


<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">A</font>
</td>

<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">B</font>
</td>

<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">C</font>
</td>
<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">Total Defect</font>
</td>
<td width="30" bgcolor=#94B6FF align="center" height="1">
<font color=white style="font-size: 8pt">Unit WDD</font>
</td>
<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">A</font>
</td>

<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">B</font>
</td>

<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">C</font>
</td>

<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">Total Defect</font>
</td>

<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">QA WDD</font>
</td>
<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">A</font>
</td>

<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">B</font>
</td>

<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">C</font>
</td>

<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">Total Defect</font>
</td>

<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt">External WDD</font>
</td>
<td width="31" bgcolor=#94B6FF align="center" height="1">
<font style="font-size: 8pt"></font><font color=white style="font-size: 8pt"></font>
</td>


</tr>
</table>


</body>

</html>

i'm sorry, I don't see how its different... well thats a lie, I can obviously find a multitude of differences. what I am trying to say is that thread describes adding new elements to an html page.

The only minor difference is that the thread has a button - you want to listen to the enter key event. Which isn't hard (add a keyPress event handler to your page). But I would recommend against this approach - as the enter key has other special meanings in html (like submitting your form if you feel the need). so unless your just interested in the idea of making a page like excell, i'd think about the user and perhaps put buttons on each line.

unless you don't mean dynamically add a new row, perhaps you mean just go to the next row?

in which case add a keypress event handler to each end of row textfield... much better UI.

Hi,
I have reused the code which was given in the link.
but there is one more problem,when I am adding a new row ,new row contains the data of the previous row.

I want the new row to be blank..
Please let me know ASAP


Thanks in advance,
Manish

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.