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.