summaryrefslogtreecommitdiffstats
path: root/Bachelor/Entwicklung webbasierter Anwendungen/Praktikum4/12_ecmascriptdom1.htm
blob: 1be4e69fda7950ec2a7e09ed8caae11e412604b1 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
	<!-- Strict nicht m�glich wegen target="_new" in form -->
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<title>Beispiele f�r ECMAScript und DOM</title>
	<style type="text/css">
	<!--


/* allgemeine Styles */
		td { font-size:0.8em; }
		td.aussen { vertical-align:top; padding:0.8em; }
		body { font-family:Arial, Helvetica, sans-serif; }
		h1 { font-size:1.2em; }
		h3 { font-size:1.0em; }
		form td { white-space:nowrap; }


/* Auf- und Zuklappen */
		span.PlusMinus { background-color:rgb(192,192,192);
			padding-left:0.2em; padding-right:0.2em; cursor:pointer;
			font-family:monospace; }
		ul.Unterpunkte { margin-top: 0.2em; margin-bottom: 0.2em; display:none; }


/* Mouseover-Effekte */
		div.ButtonNormal { background-color:rgb(192,192,192); cursor:pointer;
			text-align:center; margin-bottom:0.1em; width:30%; }
		div.ButtonOver { background-color:rgb(216,216,216); cursor:pointer;
			text-align:center; margin-bottom:0.1em; width:30%; }
		div.ButtonDown { background-color:rgb(242,242,216); cursor:pointer;
			text-align:center; margin-bottom:0.1em; width:30%; }


/* Formular */
		td.Beschriftung { text-align:left; vertical-align:top; }
		td.zentriert { text-align:center; }
		.volleBreite { width:100%; }


	-->
	</style>
	<script type="text/javascript">
	<!--


// allgemeine Funktionen

		function Initialisierung()
		{
			BuchstabenZiffernUmschaltung();
			Vorauswahl("Landwahl", "Inselwahl");
		}
		function zeigeAusnahme (Ausnahmeobjekt)
		{
			var Meldung = "Fehler: ";
			if (typeof Ausnahmeobjekt == "object") {
				// Browser werfen mitunter solche Ausnahmeobjekte aus
				for (var Attribut in Ausnahmeobjekt) {
					Meldung = Meldung + "\n" + Attribut + " = " + Ausnahmeobjekt[Attribut];
				}
			}
			else
				Meldung = Meldung + Ausnahmeobjekt;
			alert (Meldung);
		}



// Auf- und Zuklappen

		function AufZuKlappen (Kapitel)
		{
			try {   // Beispiel zur Ausnahmebehandlung
				var nPlusMinus = Kapitel.firstChild;
				var nUnterliste = Kapitel.nextSibling.nextSibling;
				var istZu = (nPlusMinus.nodeValue == "-");
				if (istZu) {
					nPlusMinus.nodeValue = "+";
					nUnterliste.style.display = "none";
				}
				else {
					nPlusMinus.nodeValue = "-";
					nUnterliste.style.display = "block";
				}
			}
			catch (Ausnahme) {
				zeigeAusnahme (Ausnahme);
			}
		}



// Auswahlhierarchie

		var Inseln_Spanien = new Array ("Ibiza", "Mallorca", "Teneriffa");
		var Inseln_Italien = new Array ("Elba", "Sardinien");
		var Inseln_Griechenland = new Array ("Korfu", "Kreta", "Rhodos", "Samos");

		function Vorauswahl(OberlisteID, UnterlisteID)
		{
			var Oberliste = document.getElementById(OberlisteID);
			var Unterliste = document.getElementById(UnterlisteID);
			var Auswahl = Oberliste.options[Oberliste.selectedIndex].text;
			var Inseln = eval ("Inseln_" + Auswahl);

			while (Unterliste.firstChild != null)
				Unterliste.removeChild (Unterliste.firstChild);
			for (i=0; i<Inseln.length; i++) {
				var neuesElement = document.createElement ("option");
 				var neuerText = document.createTextNode (Inseln[i]);
				neuesElement.appendChild (neuerText);
				Unterliste.appendChild (neuesElement);
			}
		}



// Mouseover-Effekte

		function Mouseover (Schaltflaeche)
		{
			Schaltflaeche.className = "ButtonOver";
			// Sonderfall, weil class ein reserviertes Wort ist
		}
		function Mouseout (Schaltflaeche)
		{
			Schaltflaeche.className = "ButtonNormal";
		}
		function Mousedown (Schaltflaeche)
		{
			Schaltflaeche.className = "ButtonDown";
		}
		var bgStyle = null;
		var bgColor = null;
		function Mouseup (Schaltflaeche)
		{
			if (Schaltflaeche.className=="ButtonDown") {
				bgStyle = Schaltflaeche.parentNode.style;
				if (bgColor==null)	// gegen retriggern
					bgColor = bgStyle.backgroundColor;
				bgStyle.backgroundColor = "rgb(242,216,216)";
				window.setTimeout("bgStyle.backgroundColor = bgColor;",500);
			}
			Mouseover (Schaltflaeche);
		}



// �berpr�fung von Eingaben

		function BuchstabenZiffernUmschaltung()
		{
			if (document.getElementsByName("Eingabetyp")[0].checked==true)
				document.getElementById("FormBeschriftung").firstChild.nodeValue = "Buchstaben:";
			else
				document.getElementById("FormBeschriftung").firstChild.nodeValue = "Zahl:";
   		}
		function isAlpha(Zeichen)
		{
			return (Zeichen>="a" && Zeichen<="z") || (Zeichen>="A" && Zeichen<="Z");
		}
		function OnAbschicken()
		{
			var Eingabe = document.getElementById("FormEingabe").value;
			if (document.getElementsByName("Eingabetyp")[0].checked==true) {
				// verlangt Buchstaben
				for (i=0; i<Eingabe.length; i++)
					if (!isAlpha(Eingabe.charAt(i))) {
						alert ("Bitte geben Sie nur Buchstaben ein !");
						return false; // nicht abschicken
					}
			}
			else {
				// verlangt Zahl
				if (isNaN(parseInt(Eingabe))) {
					alert ("Bitte geben Sie eine Zahl ein !");
					return false; // nicht abschicken
				}
				else if (!isFinite(parseInt(Eingabe))) {
					alert ("Diese Zahl ist au�erhalb des m�glichen Wertebereichs !");
					return false; // nicht abschicken
				}
			}
			return true; // abschicken
		}



	//-->
	</script>
</head>

<body onload="Initialisierung();">
<h1>Beispiele f�r ECMAScript und DOM</h1>

<table border="1" cellspacing="0" cellpadding="3">
<tr>



	<td class="aussen">
		<h3>

Auf- und Zuklappen<br>von Unterpunkten

		</h3>

		<div>
			<span class="PlusMinus" onclick="AufZuKlappen(this);">+</span> Fernweh
			<ul class="Unterpunkte">
			<li>in die Sonne</li>
			<li>Winterfreuden</li>
			<li>Kultur</li>
			</ul>
		</div>
		<div>
			<span class="PlusMinus" onclick="AufZuKlappen(this);">-</span> Kontakt
			<ul class="Unterpunkte" style="display:block;">
			<li>schreiben</li>
			<li>mailen</li>
			<li>Prospekte anfordern</li>
			</ul>
		</div>
		<hr><img src="images/AufUndZuklappen.gif" alt="DOM-Teilbaum">
	</td>
</tr><tr>



	<td class="aussen">
		<h3>

Auswahlhierarchie

		</h3>
		<form action="http://localhost/cgi-bin/echo.pl" method="POST">
			<table border="0">
				<tr>
					<td class="Beschriftung">W�hlen Sie erst das Land...<br>
						<select name="Land" size="3" id="Landwahl"
						  onchange="Vorauswahl('Landwahl', 'Inselwahl');">
							<option selected>Spanien</option>
							<option>Italien</option>
							<option>Griechenland</option>
		           			</select>
					</td>
				</tr>
				<tr>
					<td class="Beschriftung">...und dann die Insel:<br>
						<select name="Insel" id="Inselwahl" size="4" style="width:100%">
							<option>&nbsp;</option>
						</select>
					</td>
				</tr>
			</table>
		</form>
		<hr><img src="images/Auswahlhierarchie.gif" alt="DOM-Teilbaum">
	</td>
</tr><tr>



	<td class="aussen">
		<h3>

Mouseover-Effekte

		</h3>
		<div class="ButtonNormal" onmouseover="Mouseover(this);" onmouseout="Mouseout(this);"
			onmousedown="Mousedown(this);" onmouseup="Mouseup(this);">
			Suchen
		</div>
		<div class="ButtonNormal" onmouseover="Mouseover(this);" onmouseout="Mouseout(this);"
			onmousedown="Mousedown(this);" onmouseup="Mouseup(this);">
			Buchen
		</div>
		<div class="ButtonNormal" onmouseover="Mouseover(this);" onmouseout="Mouseout(this);"
			onmousedown="Mousedown(this);" onmouseup="Mouseup(this);">
			Kontakt
		</div>
		<hr><img src="images/Mouseover.gif" alt="DOM-Teilbaum">
	</td>
</tr><tr>



	<td class="aussen">
		<h3>

�berpr�fung von Eingaben

		</h3>
		<form action="http://localhost/cgi-bin/echo.pl" method="POST" target="_new"
				onsubmit="return OnAbschicken();" onreset="BuchstabenZiffernUmschaltung();">
			<table border="0">
				<tr>
					<td id="Tab2Spalte1">nur Buchstaben</td>
					<td>
					   <input type="radio" name="Eingabetyp" value="Buchstaben" checked
							onclick="BuchstabenZiffernUmschaltung();">
					</td>
				</tr>
				<tr>
					<td>nur Zahlen</td>
					<td>
					   <input type="radio" name="Eingabetyp" value="Ziffern"
							onclick="BuchstabenZiffernUmschaltung();">
					</td>
				</tr>
				<tr>
					<td id="FormBeschriftung">???:</td>
					<td><input type="text" class="volleBreite" size="27"
            					name="Eingabe" id="FormEingabe" value="">
					</td>
				</tr>
				<tr>
					<td></td>
					<td>
					   <input type="submit" class="halbeBreite" name="B1" value="Abschicken">
					</td>
				</tr>
			</table>
		</form>
		<hr><img src="images/Ueberpruefung.gif" alt="DOM-Teilbaum">
	</td>
</tr>
</table>
</body>
</html>