There is a form and a button above it. Clicking the button displays the values ​​for the first and second (zero and first) fields — email and username .

 document.querySelector("#validate").addEventListener("click", function(event) { console.log(document.querySelector("form").elements[0].value); console.log(document.querySelector("form").elements[1].value); }); 
 <button id="validate">Validate Form!</button> <form action="" method="POST" autocomplete="off"> <p><label for="email">Email</label></p> <p> <input type="email" name="email" id="email"> </p> <p><label for="username">Username</label></p> <p> <input type="text" name="username" id="username"> </p> <p><label for="password">Password</label></p> <p> <input type="password" name="password" id="password"> </p> <p><label for="password-conf">Password Confirmation</label></p> <p> <input type="password" name="password-conf" id="password-conf"> </p> <p> <input type="submit" name="commit" value="Submit"> <input type="submit" name="commit2" value="Submit2"> <input type="submit" name="commit3" value="Submit3"> </p> </form> 

Question: why, if you enter spaces in the first and second fields, the result for the first line is nothing, and for the second, are these entered spaces?

Note: even if the line does not contain only spaces, but begins with spaces, and ends with some set of characters, the spaces from the beginning of the first line will still disappear.

Browser - Chrome 58.

    1 answer 1

    type="email" https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email

    Any trailing and leading whitespace is removed.

    Whitespace at the beginning and end of each address is automatically deleted.

    • "The <input> element \ 's value attribute \' s value contains a DOMString which is automatically conforming to email syntax.". It turns out that novalidate on the form does not matter? - smellyshovel
    • And yes, he is there (I, not here in the snippet). - smellyshovel
    • @smellyshovel did not check it. Answer the question about spaces. - Igor
    • Well, apparently, it turns out that novalidate only annoying standard "alerts" disables, but not this behavior. Well, thanks. The question is, perhaps, reformulated in order to be indexed normally in the search. - smellyshovel