libjsform | manual | examples | download | browser_notes | license
The basic workings are in checkrequired.js, which is less than 3 KB and provides a required fields checker. You can use this file alone and quickly create a form with go / no go validation. All the other files are extensions which you can include as you need. To save on bandwidth, you can copy and paste the functions you need from the extensions directly into your HTML page or create your own custom library file with just the functions you use.
The messages.js file provides a simple framework for generating custom error messages using the results of check().
The english.js file contains additional message-generating tools which are specific to English.
Adds thevalue to the end of thearray. Provided because IE 5.2 Mac and others do not have Array.push()
Returns the label of a select-one or select-multiple option. If a label is not explicitly defined, then the text inside the option tag is returned.
Returns the value of a select-one or select-multiple option. If a value is not explicitly defined, it returns the optionlabel()
Returns the value of any type of form field. For select-multiple, it returns a comma-separated list of all selected values.
for(var i=0; i<theform.elements.length; i++) { alert(theform.elements[i].name + " = " + fieldvalue(theform.elements[i])); }
If you are working with a radio group, pass a single radio input only, such as theform.radiobuttons[0]
Returns an array of values of of any form field array. Select-multiple fields are only one element and within that element they are comma-separated output from fieldvalue().
alert(theform.radiobuttons); alert(theform.select_or_type);
If you are working with a radio group, pass a field array such as theform.radiobuttons
It is also useful for having a select-one with options and a text input for "other", and you give them the same name attribute so then you can say arrayvalue(theform.select_or_type) and get both values.
Returns the value of any form field as a string (multiple values are separated by commas). This is the most convenient way to get the value of any field, including radio groups. It's like arrayvalue() but returns a comma-separated string instead of an array, and works also for single-input fields.
Returns true if the given field is not blank or has a value that is not ignored. For field groups, it returns true if at least one field in the group has a value.
Usage: required=true or required=group. required=false and required=no may be useful for scripting.
<input type="hidden" name="RSVP" value="" label="RSVP selection" required="group"> RSVP: <INPUT NAME="RSVP" TYPE="radio" VALUE="I'm coming! I'm coming!">I'm coming! I'm coming!<BR> RSVP: <INPUT NAME="RSVP" TYPE="radio" VALUE="Count me out, I can't handle it">Count me out, I can't handle it<BR>
Returns an array of error objects {target=thefield; error=type} for fields that do not pass validation. The validators object has attributes which are expected in form fields (required, email, range, ...) and their values are functions which can accept a form field and return a boolean true if its data is valid.
Usage: check(theform, {required:validaterequired})
Given a specific form field like you would pass to fieldvalue(), returns the field's label.
A convenient way to specify message-generating functions for errors, like validators are specified for check(). If a formatter is not found for a certain error type, the field label of the target alone is used as the message.
Usage: messages( check(theform,{required:validaterequired}), {required:validaterequired_error} )
This function takes the errors array generated by check() and reformats it so that instead of {error:type, target:field} objects it contains {error:type, target:fieldarray} objects which you can then pass on to alternate message-generating functions that work with groups of similar errors.
Returns a string verb appropriate for the given field's type, such as "fill in" for text, "select" for checkboxes, etc.
Given an empty list, returns "". Given a returns "a". Given a,b returns "a and b". Given a,b,...,x returns "a, b, ... and x".
Copyright (C) 2009 Jonathan Buhacoff