PageSourceSearch

https://link.newsletter.ksc.de/u/nprefill.js

js ksc.de collected 2026-10-01 12:14:04 UTC 3,107 bytes, 133 lines download raw bytes

1// <input type=text>
2function setText(obj, value)
3{
4		obj.value = value;
5}
6
7// <input type=checkbox>
8function setCheckBox(obj, value)
9{
10	if(obj.value == value) 
11		obj.checked = true;
12}
13
14// <select>
15function setSelect(obj, value, byValue)
16{
17		for(var i=0; i<obj.options.length; i++) {		
18				if((byValue && obj.options[i].value == value) || (!byValue && obj.options[i].text == value))
19						obj.selectedIndex = i;
20		}
21}
22
23// <input type=radio>
24function setRadio(obj, value)
25{
26		if(obj.value == value)
27				obj.checked = true;
28}
29
30// <textarea>
31function setTextArea(obj, value)
32{
33		obj.value = value;
34}
35
36// split date param and set all the input fields
37function setDate(name, value)
38{
39		var parts = value.split("-");
40		if(parseInt(parts[2]))
41				setValue(name, parseInt(parts[2]));
42		if(parseInt(parts[1]))
43				setValue(name, parseInt(parts[1]), 1);
44		setValue(name, parts[0]);
45}
46
47// find element with the given name and set its value
48function setValue(name, value, byValue)
49{
50		var col = document.getElementsByName(name);
51		if(col.length) {
52				for(var i=0; i<col.length; i++) {
53					
54						if(col[i].tagName == 'INPUT') {
55								if(col[i].type == 'text' || col[i].type == 'hidden' || col[i].type == 'password')
56										setText(col[i], value);
57								else if(col[i].type == 'checkbox')
58										setCheckBox(col[i], value);
59								else if(col[i].type == 'radio')
60										setRadio(col[i], value);
61						} else if(col[i].tagName == 'SELECT') {
62								setSelect(col[i], value, byValue);
63						} else if(col[i].tagName == 'TEXTAREA') {
64								setTextArea(col[i], value);
65						}
66						
67				}
68		}
69}
70
71// remove leading and trailing spaces
72function ltrim(s)
73{
74		if(!s) return '';
75		return s.replace(/^\s*/, "");
76}
77
78function rtrim(s)
79{
80		if(!s) return '';
81		return s.replace(/\s*$/, "");
82}
83
84function trim(s)
85{
86		return rtrim(ltrim(s));
87}
88
89// php's urlencode replaces spaces with "+"... the javascript's unescape doesn't decode it back
90function urldecode(str)
91{
92		if(!str) return '';		
93		return unescape(str.replace(/\+/g, ' '));		
94}
95
96// add this function to the body onLoad event handler to prefill all the elements with the given params
97function preFill(utf8)
98{
99		var url = document.URL;	
100		
101		var url_parts = url.split("?");
102		
103		if(url_parts.length == 2) {
104			
105				var search = url_parts[1];
106				
107				var params = search.split("&");
108				
109				for(var i=0; i<params.length;i++) {
110						var param = params[i].split("=");
111						var name = trim(urldecode(param[0]));
112						var value = utf8 ? trim(decodeURIComponent(param[1].replace(/\+/g, '%20'))) : trim(urldecode(param[1])); 
113						var elm;
114						var tmp;
115						
116						if(dateFields[name]) {
117								setDate(name, value);
118						} else if(multiFields[name]) {
119							eval("elm=arr_"+multiFields[name]+";");
120							for(tmp in elm) {
121								if(value.indexOf(tmp) > -1) {
122									setValue(name, elm[tmp]);									
123									value = value.substr(0,value.indexOf(tmp))+value.substr(value.indexOf(tmp)+tmp.length,value.length);									
124								}
125							}
126						}
127						else
128								// finaly, set the standard params
129								setValue(name, value, 0);
130				}
131		}
132}
133

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.