Forms JavaScript Code Snippets

These snippets (and a few tutorials) all deal with Javascript forms. We’ll show you some really neat forms that keep you from receiving bogus information as well as others that are just fun to play with (test personal info).

Results via Envato Market

Validates an input field to make sure that only a number or character is entered. If you enter a number or a letter everything you can continue on. But, try entering another value like an exclamation point (!), an ampersand (&), or a dollar sign ($) and see what happens. It even highlights the incorrect entry field for you. Nice!

Using an external JavaScript file, simply define the rules for how each field should be validated and you’re set. Piece of cake! And since it is it’s own .js file, it’s easy to use the code on every page of your site. Currently only validates text, numbers and e-mail addresses.

Use JavaScript to ensure that all elements of a form are properly filled out before they can be mailed to you. This definitely saves me from getting a lot of junk mail….

Dates are validated and formatted in your form. Supports over a dozen different date formats, and formats the date properly in United States or European date formatting styles depending on how the script is configured. A dateCheck function also is included if you wish to compare two dates. Wow!

A script to put on your HD that computer user can log in an out and it will keep record of the time’s that got on, off, and how much time they had spent on. This only work perrmitting the program is left on that page.

This Script Alows Users To Enter A Username That They Will Be Nown As And A Password But If They Dont Type The Right Password They Dont Get In.

“This is an advanced script which, in addition to “”standard”” information like a user’s browser, defines a used API too. In Netscape it works incorrectly.”

A simple script that takes a user to a page of what password and user name they submit.

Use this script to add and subtract items in different fields. Changes made can be displayed for each field.

In this order form, the cost for each item is totaled as the items are selected and deselected. This is done without refreshing the entire page in order to save other form information. Heavily commented.

Allowing visitors to upload files through web forms on your site is useful, but how do you limit the types of files they can upload? This script only allows visitors to upload files that end with the file extensions you want, such as .gif and .jpg, etc. Easy!