var allchk = document.getElementsByName("contacts")
what is "contacts" in above line

Recommended Answers

All 5 Replies

contacts would be the HTML element that you are gathering. I do so believe that it's from the ID=contacts, identifier.

So say for example <p id=contacts>insert stuff here</p>

getElementById returns all elements with element name attribute as specified in the double quotes.
Take a look at quote from

The getElementsByName(name) method takes a string name, and must return a live NodeList containing all the HTML elements in that document that have a name attribute whose value is equal to the name argument (in a case-sensitive manner), in tree order. When the method is invoked on a Document object again with the same argument, the user agent may return the same as the object returned by the earlier call. In other cases, a new NodeList object must be returned.


Contacts is our html element name ..
Your element will be like this <input type = "text" name = "contacts" />

To clarify... There are some confusing responses in this thread. The OP is asking about getElementsByName not getElementById.

document.getElementsByName() returns a HTMLCollection of all the elements with a given value for the name attribute, commonly used when targeting input elements.

@JorgeM:- typing error ,i mean there getElementsByName.

Be a part of the DaniWeb community

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