my question is if more than one id can be placed in an input because I have a function in javacript that I command to call in the id of an input type text but in that input I also have to have the id with the variable of my database data. where the data will be inserted.
this is the input code:
<td>
<h5>Avance 1:</h5>
</td>
<td>
<input type="text" name="CONTRATO" id="total" size="5" value="<%= rs.getString(5) %>" disabled="0">
</td>
my javascript function name is total
and my database variable is calledcontrato
How could I do it in that case?
I leave you an example with a div that has 2 id, the first call with the first id works, instead when the second div is called there is an error!!! }
conclusion: there cannot be 2 id in an element.
Answering the question, you can NOT put more than one id to an element and also this id has to be unique in the entire document.
A solution to assign more data in the element is to use the
data
. For example you can create inputs like this:And with Javascript you would get the values as follows:
By definition a function, object, class, etc. It must have a unique Name which serves as an Identifier for future references and calls that may be made depending on the case.
What can be done (but I don't recommend it) is to use a numerator for the identifier, for example:
What is done here is to have two variables with the same id, we only add a numerator, in practice this is not recommended because it can cause misunderstandings later and possible bugs.
I hope the clarification will serve you, greetings.
P.S. You can read this article about Identifiers if you are interested.
As you have already been told, you definitely cannot have the same ID for different elements, it is a unique and unrepeatable identifier, what you could do is put another input and hide it and there you send the ID you need and that's it.
I see that everyone told you that you can NOT put two id that is correct but you can create a new attribute
objectid
for example and play with itWhat you can use is the
name
.