/
1002.html
58 lines (55 loc) · 1.15 KB
/
1002.html
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
<HTML>
<HEAD>
<TITLE>Squash Bugs!</TITLE>
<SCRIPT>
function countWords(str){
var count = 0;
words = str.split(" ");
for (i=1 ; i < words.length ; i++){
alert("The count is " + i + " ; current word is " + words[i]);
// inner loop -- do the count
if (words[i] != "")
count += 1;
}
document.theForm.results.value =
"There are " +
count +
" words in the text string you entered!";
}
</SCRIPT>
</HEAD>
<BODY>
<H1>
Squash Those Bugs!
</H1>
<FORM name="theForm">
<TABLE>
<tr><td colspan=5>
Enter a text string:
</td></tr><tr><td colspan=5>
<TEXTAREA name=inStr rows=5 cols=90>
</TEXTAREA>
</td></tr>
<tr>
<td colspan=4>
<INPUT type=button value="Count Words" onClick="countWords(document.theForm.inStr.value)";>
</td>
<td>
<INPUT type=button value="Clear" onClick='document.theForm.inStr.value=""';>
</td>
</tr>
<tr><td colspan=5>
<br><hr>
Results<br>
</td></tr>
<tr><td colspan=5>
<TEXTAREA name=results rows=5 cols=90>
</TEXTAREA>
</td></tr>
<tr><td colspan=5>
<INPUT type=button name="theButton" value="Clear Results" onClick='document.theForm.results.value=""';>
</td></tr>
</TABLE>
</FORM>
</BODY>
</HTML>