I want to validate an HTML form to ensure an <input> has a value. In JavaScript, what is the value of an empty field in a form: null or the empty string ("")?
3 Answers
For any input element, value is always a string. This means you can expect it to be "", when empty.
See the docs for HTMLInputElement on the Mozilla Developer Network, or the relevant part of the HTML4 spec.
document.getElementById(idname).valueto see the value.