JavaScript/Forms

Many users are familiar with filling out forms on a web page and then hitting the "submit" button. There are at least 2 ways Javascript can improve this process:

  • Javascript can be used to check the data before it is sent to the server.
    • JavaScript can pre-validate the data, to catch common errors and suggest improvements immediately while the user is filling out the form, before the user clicks the "submit" button.
    • JavaScript can take text typed into a textarea and pre-render it in a separate area of the page, so people can see how it will be rendered and formatted before clicking the "preview" button.[1][2][3]
    • JavaScript can give a live wordcount or character count of text typed into a textarea.[4][5][6][7]
  • Sometimes a web site does a "online" calculation involving only a small amount of data and returns the result to the user. In this case, Javascript can intercept the "submit" button, do the entire calculation locally in the browser. The user gets the results more or less immediately, rather than waiting for the data he typed in to be sent to the server, waiting for the server to get around to processing that data, and waiting for the data to come back from the server.


Many people recommend keeping all the content accessible to people with disabilities and to people who have JavaScript turned off. One way to do that is to start with standard HTML forms, and then add unobtrusive JavaScript to improve the user experience to people who have JavaScript turned on. The system should degrade gracefully, keeping all the of the content available (and validating user data, if necessary), whether or not any or all of the JavaScript runs successfully.

Further readingEdit

Last modified on 31 December 2013, at 11:17