S
S
sinelnikov-web2022-03-12 21:05:03
HTML
sinelnikov-web, 2022-03-12 21:05:03

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)
        }
    })

Or something similar (not so important) and as a result, the user will not be able to enter other characters other than numbers in the same way.
Can anyone judge who is right in this situation. Please justify your answers. I understand that this is rather just another topic for holivar, but still, I'm interested to hear the opinions of other people.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lil_koi, 2022-03-12
@lil_koi

But it seems to me that the type attribute does not specify the data type, but only the data input format.

well, not really, you can set either the data entry format (date, phone, number, or just a string, etc.), or the button type or the hidden type and the field will not be displayed at all, but the data will be there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question