form.js defines the following functions:
makeSearchString()makeSearchString(name, value,...)
nameA string to be associated with value. Similar to the name attribute of a form element.
valueA string to be associated with name. Similar to the value attribute of a form element.
A string of the form '?name1=value1&name2=value2'.
makeSearchString() takes an even number of arguments and forms a valid query string as would be created by submitting a form using the 'get' method. Odd-numbered arguments are considered names and even-numbered ones are values. Each argument is url-encoded and pairs are joined with an =. All the sets of pairs are then concatenated using &s. Finally, a ? is prepended to the string and the string is returned.
gatherFormData()gatherFormData(form)
formA reference to a form object.
A string of the form '?name1=value1&name2=value2' for all the elements in the form.
gatherFormData() forms a valid query string as would be created by submitting the form using the 'get' method. Names and values are url-encoded and pairs are joined with an =. All the sets of pairs are then concatenated using &s. Finally, a ? is prepended to the string and the string is returned.
clearForm()clearForm(form)
formA reference to a form object.
Nothing.
Clicking a form's reset button (or invoking it's reset() method) will reset the form elements back to the values they contained when the page was loaded. If any text boxes have value attributes, or radio or checkboxes have checked attributes, or select options have selected attributes, or textareas have text between the open and close <textarea> tags, resetting a form doesn't clear it. In the case where it is preferable to clear a form, clearForm() can be used.
getSearchAsArray()getSearchAsArray()
An array of all the values passed to the current page in the form of a 'get' query string indexed by their corresponding names.
getSearchAsArray() gathers all the name and value pages passed to the current page in the form of a 'get' query string and makes them available in an associative array. This removes the need to parse the location.search string for the value associated with a known name. Values can be extracted from the array by using the associated name as an index to the array.
The script automatically calls this function and creates an array called query to store the name and value pairs. As an example, the value associated with the name bob is stored in query['bob'].
This script is released under a Creative Commons License.