Answer the question
In order to leave comments, you need to log in
What does the type attribute on input actually do?
Good afternoon guys, I'm in my second year of bachelor's degree and there was a small topic for holivar.
The teacher says that the type attribute of input specifies the data type for this element. The html spec says something like this: "The type attribute controls the data type (and associated control) of the element."
But it seems to me that the type attribute does not specify the data type, but only the data input format.
My position is based on the following arguments:
1) There are no data types in HTML as such.
2) In JavaScript, which already has data types, any data received from input comes in the form of a string, regardless of the value of the type attribute.
From my point of view, I might as well write something like this:
document.getElementById('test').addEventListener('input', (e) => {
if (isNaN(e.target.value)) {
e.target.value = e.target.value.slice(0, e.target.value.length - 1)
}
})
Answer the question
In order to leave comments, you need to log in
But it seems to me that the type attribute does not specify the data type, but only the data input format.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question