aboutsummaryrefslogtreecommitdiffstats
path: root/offline-submit/collect-inputs.js
blob: d6a2b47a3e49f402c2ce14a7822cb42738e2ee3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
bzPage.prototype.collectInputs = function (form) {

// form.elements array of all controls ... no, forEach though
// INPUT, SELECT, TEXTAREA, and BUTTON
// each interesting control of them have NAME and VALUE
// You can access a particular element by using either an index or the element name or id.
//
// https://developer.mozilla.org/en/DOM/form
// form.elements.querySelectorAll("*[name]")

    var x=this.dok.getElementById("myForm");
for (var i=0;i<x.length;i++)
{
document.write(x.elements[i].value + ", " + x.elements[i].tagName + ", " + x.elements[i].name);
document.write("<br />");
}

}

// INTERESTING: http://www.quirksmode.org/js/forms.html

// Example onsubmit handler

function checkscript() {
	if (some value is/is not something) {
		// something is wrong
		alert('alert user of problem');
		return false;
	}
	else if (another value is/is not something) {
		// something else is wrong
		alert('alert user of problem');
		return false;
	}

	// If the script makes it to here, everything is OK,
	// so you can submit the form

	return true;
}

// with XPCNativeWrappers you cannot use document.formname.inputname.value
var form = document.forms.namedItem("gs");
var input = form.elements.namedItem("q");
var q = input.value;