Javascript Tutorials

ListBox Page Redirection

SmartWebby's Guide to Dynamic HTML (DHTML)

ListBox Page Redirection

In forms when using text boxes or text areas with limited character length (usually needed for forms that submit data to a database) it is always a good idea to tell the user how many characters they have remaining. The following example shows how you can do this. This is a very simple and cute idea to help the user know exactly how many characters he can type further. Do these small add-ons to your forms and they will look really professional.

Example

Example of displaying how many characters remain while filling data into a text box field

Maximum Number of characters for this text box is 255.


  You have 255 characters remaining for your description...


.

Cut and Paste Code

Title

Cut 'n' paste code for the above Example

Java-script Code

HTML Code

Explanation of the Code

The java-script has two functions:

  • function SetChecked is used to check and clear the check boxes : Here we find all elements in the form which are check boxes with a given name. If the boxes need to be checked the property "checked" of the elements is set to 1 and 0 if they are to be cleared.
  • function ValidateForm is used to validate the form to see if at least one check box is ticked on submission : Here we check all the check boxes with a given name to see if at least one is checked. If one is found then we return true to the form submission else we return false and an alert message.
Please like, +1, link to and share this SmartWebby resource if you found it helpful. Thanks!