/* js functions for forms */ /* display a simple form from a ejs Form object caller should fill in f.name = form name f.action = action to be taken on submit (optional, defaults to current page) f.class = css class (optional, defaults to 'form') f.submit = an array of submit labels f.add(name, label, [type], [value]) = Add another element f.element[i].label = element label f.element[i].name = element name (defaults to label) f.element[i].type = element type (defaults to text) f.element[i].value = current value (optional, defaults to "") */ function form_display() { var f = this; var i, size = 20; write('
\n"); } function __addMethod(name, label) { var f = this; var i = f.element.length; f.element[i] = new Object(); f.element[i].name = name; f.element[i].label = label; f.element[i].type = "text"; f.element[i].value = ""; if (arguments.length > 2) { f.element[i].type = arguments[2]; } if (arguments.length > 3) { f.element[i].value = arguments[3]; } } /* create a Form object with the defaults filled in, ready for display() */ function FormObj(name, num_elements, num_submits) { var f = new Object(); f.name = name; f.element = new Array(num_elements); f.submit = new Array(num_submits); f.action = session_uri(request.REQUEST_URI); f.class = "defaultform"; f.add = __addMethod; for (i in f.element) { f.element[i] = new Object(); f.element[i].type = "text"; f.element[i].value = ""; } f.display = form_display; return f; }