JavaScript/Forms
Appearance
Many users are familiar with filling out forms on a web page and then hitting the "submit" button. There are at least two 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 text area 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 text area.[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 content available (and validating user data, if necessary), whether or not any or all of the JavaScript runs successfully.
Further reading
[edit | edit source]- JavaScript/Working With Files mentions one use of HTML forms
- HyperText Markup Language/Forms explains how to write "plain" forms without JavaScript.
References
[edit | edit source]- ↑ "How can I display the HTML content of a Text Area within a div as HTML content and not text?"
- ↑ Andrey Fedoseev. "jQuery plugin to add realtime preview panel to text areas, similar to StackOverflow edit interface"
- ↑ Guillaume DE LA RUE. "A Markdown live editor in JS".
- ↑ Sacha Schmid. JavaScript word count
- ↑ Drew Schrauf. "JavaScript Wordcount That Works".
- ↑ "JavaScript word-count for any given DOM element"
- ↑ Jake Rocheleau. "Building a Live Text area Character Count Limit with CSS3 and jQuery"