Skip to content
Advertisement

Assign sequential numbering to elements [closed]

I am trying to iterate through elements to add sequential numbering to them.

Example: I have 6 input elements, I want to count how many inputs there are and then change their name to match their number “name=input1”, “name=input2”, and so on. I’m using a for loop to reset this each time an element is added or removed.

Here is the function I’ve been trying (and failing) to implement:

JavaScript

Advertisement

Answer

Something like this would work:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement