Assign id to Input element which has only name attribute

user3782114

I have set of table rows, each row has input elements defined with only name[] attribute,

<tr id="1">
<td><input name="billdate[]" required="required" class="form-control" placeholder="DD/MM/YYYY"></td>
<td><input class="form-control" name="amt[]" required="required"  value="0" type="text"></td>
<td><input name="gst[]" class="form-control" value="0" required="required"  type="text"></td>
<td><input name="netamt[]" class="form-control" required="required" value="0"  type="text"></td>
<td><input name="glcode[]" class="form-control" required="required" value=""  type="text"></td>
</tr> 

I have added JavaScript code to clone table row, code written below

var row = document.getElementById("1"); // find row to copy
      var table = document.getElementById("asd"); // find table to append to
      var clone = row.cloneNode(true); // copy children too
      clone.id = document.getElementById("setid").value; // change id or other attributes/contents
      table.appendChild(clone);

cloning is working fine, but the problem is that I want to assign unique ids to each input element. Is there any easy way to do this? I tried several ways to add but did not succeeded.

Edwin Dijas Chiwona

Not sure if this is what your looking for. But looping through childnodes and getting input element then assigning ID seems to do the trick.

var row = document.getElementById("1"); // find row to copy
var table = document.getElementById("asd"); // find table to append to
var clone = row.cloneNode(true); // copy children too
clone.id = 'blue';//document.getElementById("setid").value;'' // change id or other attributes/contents
var children = clone.children
for( var t = 0 ; t < children.length; t++ ){
      children[t].children[0].id = 'id-'+t;
 }
//Debugging
  console.dir( clone );
  table.appendChild(clone);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to select element which doesn't has Id attribute?

From Dev

How to locate the element which has only one attribute and is duplicate with other elements in the webpage?

From Dev

How can I assign select2 plugin to select element which has plugin options as json object at data attribute?

From Dev

How to get an input element that has an array name which I have assigned the value of the index?

From Dev

Accessing JSON element which has a number for the name

From Dev

Getting current element value among multiple elements which has same class name with no id

From Dev

Should I create a table which only has id and name and belongs to users table with one to one?

From Dev

Check if element has child node by id name

From Dev

Override pseudo element ::before if the element has an ID attribute

From Dev

How to select all member which has a given attribute name with UDA?

From Dev

How to get the next element which has the attribute tabindex

From Dev

Assign a value to an attribute name

From Dev

get value of input element with "id" or "name"

From Dev

How to get element by attribute name which ends with defined word

From Dev

Is it possible add an id to an element which already has an id

From Dev

Is it possible add an id to an element which already has an id

From Dev

Selecting an element by its attribute when it has a colon in its name

From Dev

JAXB Marshals root element without a close tag if it only has an attribute

From Dev

Execute Change event only if element has a specific attribute

From Dev

Which attribute is applied if both id and class are specified for an element and why?

From Dev

Implications when an input has the same name as another input's ID

From Dev

Check in controller which input element has been modified

From Dev

How to add a class to an element which has a class name not in array

From Dev

Find an html element which has a class but the class name is varying or unknown

From Dev

How to add a class to an element which has a class name not in array

From Dev

Grab id of a form that has a child input with a name="id"

From Dev

Get Input tag Attribute ID name at Runtime in Meteor JS

From Dev

Getting class or ID name of an element based on the value of a particular attribute

From Dev

navigate to the element that has an id same to the data-id data attribute of the click element

Related Related

  1. 1

    How to select element which doesn't has Id attribute?

  2. 2

    How to locate the element which has only one attribute and is duplicate with other elements in the webpage?

  3. 3

    How can I assign select2 plugin to select element which has plugin options as json object at data attribute?

  4. 4

    How to get an input element that has an array name which I have assigned the value of the index?

  5. 5

    Accessing JSON element which has a number for the name

  6. 6

    Getting current element value among multiple elements which has same class name with no id

  7. 7

    Should I create a table which only has id and name and belongs to users table with one to one?

  8. 8

    Check if element has child node by id name

  9. 9

    Override pseudo element ::before if the element has an ID attribute

  10. 10

    How to select all member which has a given attribute name with UDA?

  11. 11

    How to get the next element which has the attribute tabindex

  12. 12

    Assign a value to an attribute name

  13. 13

    get value of input element with "id" or "name"

  14. 14

    How to get element by attribute name which ends with defined word

  15. 15

    Is it possible add an id to an element which already has an id

  16. 16

    Is it possible add an id to an element which already has an id

  17. 17

    Selecting an element by its attribute when it has a colon in its name

  18. 18

    JAXB Marshals root element without a close tag if it only has an attribute

  19. 19

    Execute Change event only if element has a specific attribute

  20. 20

    Which attribute is applied if both id and class are specified for an element and why?

  21. 21

    Implications when an input has the same name as another input's ID

  22. 22

    Check in controller which input element has been modified

  23. 23

    How to add a class to an element which has a class name not in array

  24. 24

    Find an html element which has a class but the class name is varying or unknown

  25. 25

    How to add a class to an element which has a class name not in array

  26. 26

    Grab id of a form that has a child input with a name="id"

  27. 27

    Get Input tag Attribute ID name at Runtime in Meteor JS

  28. 28

    Getting class or ID name of an element based on the value of a particular attribute

  29. 29

    navigate to the element that has an id same to the data-id data attribute of the click element

HotTag

Archive