Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Found 2 elements with non-unique id

I am getting the following warnings when we use with the same id names in two different form tags.

[DOM] Found 2 elements with non-unique id

Here is my HTML snippet:

               <div class="modal-dialog">
                    <form action="" method="post" id="myid-1" name="myid-1">
                        <input type="text" class="form-control" id="Job_Name" name="Job_Name" required="">
                        <label for="Job_Name">Job Name<span class="text-danger">*</span></label>
                        <button type="submit">Submit</button>
                    </form>
                </div>

                <div class="modal-dialog">
                    <form action="" method="post" id="myid-2" name="myid-2">
                        <input type="text" class="form-control" id="Job_Name" name="Job_Name" required="">
                        <label for="Job_Name">Job Name<span class="text-danger">*</span></label>
                        <button type="submit">Submit</button>
                    </form>
                </div>

How do I resolve "Found 2 elements with non-unique id" warnings?

like image 974
sridharnetha Avatar asked Oct 09 '20 05:10

sridharnetha


3 Answers

you need to change id="Job_Name" to be unique e.g. id="Job_Name1" id="Job_Name2" etc. as ID must be unique in the DOM.

It will create conflict when you want to select elements using document.getElementById('Job_Name') or using jQuery $('#Job_Name') as you wont be able to get the second or other elements with same id. you will need to use index and querySelectorAll which will then defeat the purpose of using Id at first place.

like image 93
sandeep joshi Avatar answered Nov 18 '22 06:11

sandeep joshi


 <input type="text" class="form-control" id="Job_Name" name="Job_Name" required="" >

Duplicate input tag in two different forms

You have to use different id for different elements

like image 35
Dibash thapa Avatar answered Nov 18 '22 05:11

Dibash thapa


<input type="text" class="form-control" id="Job_Name" name="Job_Name" required="">

You need to change de id for each input

like image 1
JesusAlmeda Avatar answered Nov 18 '22 06:11

JesusAlmeda