libjsform | manual | examples | download | browser_notes | license
2004-12-29 notes on the validation library
This is a separate file so that comments in the javascript file are kept to a minimum.
function optionvalue(theoption)
// returns a string with the value of given <select> option
function formvalue(thefield)
// you can pass a specific element such as form.radiobuttons[0] or a general field such as form.radiobuttons
// if you pass a general field array then any empty values are discarded (you won't get extra commas).
// if you're concerned about that, then use the arrayvalue function directly.
function validaterequired(thefield)
// can expand this to also trim spaces and THEN check for blankness...
// return _removeSpaces(fieldvalue(thefield)).length > 0 ? true : false;
/*
// define the _removeSpaces(value) function
function _removeSpaces(v){
// remove all spaces
while( v.indexOf(" ") > -1 ) v = v.substring( 0, v.indexOf(" ") ) + v.substring( v.indexOf(" ")+1 );
return v;
}
*/
compatibility:
As far as I know, the script functions the same way on the following browsers:
IE 5.2 Mac, Safari 1.2.4 Mac, Camino 0.8 Mac, IE 6 WinXP
use custom-defined push(array,value) instead of array.push(value) so you
will not get errors on IE 5.2 for Mac and others that have only basic/early
javascript support
The Array.pop() function is not available on IE 5.2 Mac so use var last = thelist[thelist.length-1]; thelist[thelist.length-1] = null;
give attributes a value so they will be detected on IE 5.2 for Mac
<input type="text" name="yourname" required=true> works on IE for Mac and Safari
<input type="text" name="yourname" required> works on Safari but not IE for Mac
option values and labels:
// there's a difference between how IE 5.2 for Mac and Safari for Mac treat
// undefined option values. IE says they are defined as "" and Safari says
// they are null. So to make things reliable, we'll ignore defined empty
// values and fall back to the label. You need to recognize this or provide
// non-empty invalid values for yourself.
// For example, turn this:
// <select required="true"><option value="">-select-</option><option>value1</option>...</select>
// into this:
// <select required="true" ignore="-select-"><option>-select-</option><option>value1</option>...</select>
Use the "ignore" validator to treat "-select-" as not-selected in javascript.
Copyright (C) 2009 Jonathan Buhacoff