5 var testField
= document
.getElementById('t1');
6 var results
= document
.getElementById('result');
8 testSelectionRange(1, 0, 0, 0, 0, testField
, results
);
9 testSelectionEnd(2, 17, 0, 17, testField
, results
);
10 testSelectionStart(3, 1, 1, 17, testField
, results
);
11 testSelectionRange(4, 10, 3, 3, 3, testField
, results
);
12 testSelectionEnd(5, 2, 2, 2, testField
, results
);
13 testSelectionRange(6, 5, 4, 4, 4, testField
, results
);
14 testSelectionRange(7, -5, -4, 0, 0, testField
, results
);
15 testSelectionRange(8, -5, 80, 0, 20, testField
, results
);
16 testSelectionRange(9, 3, 12, 3, 12, testField
, results
);
20 function testSelectionRange (testNumber
, start
, end
, expectedStart
, expectedEnd
, tf
, res
)
23 tf
.setSelectionRange(start
, end
);
24 res
.innerHTML
= res
.innerHTML
+ "<br>Test " + testNumber
+ ": setSelectionRange(" + start
+ ", " + end
+ ")";
25 if (tf
.selectionStart
== expectedStart
&& tf
.selectionEnd
== expectedEnd
)
26 res
.innerHTML
= res
.innerHTML
+ "<br>Passed.<br>";
28 res
.innerHTML
= res
.innerHTML
+ "<br>Failed.<br>";
31 function testSelectionStart (testNumber
, start
, expectedStart
, expectedEnd
, tf
, res
)
33 tf
.selectionStart
= start
;
34 res
.innerHTML
= res
.innerHTML
+ "<br>Test " + testNumber
+ ": selectionStart = " + start
;
35 if (tf
.selectionStart
== expectedStart
&& tf
.selectionEnd
== expectedEnd
)
36 res
.innerHTML
= res
.innerHTML
+ "<br>Passed.<br>";
38 res
.innerHTML
= res
.innerHTML
+ "<br>Failed.<br>";
41 function testSelectionEnd (testNumber
, end
, expectedStart
, expectedEnd
, tf
, res
)
43 tf
.selectionEnd
= end
;
44 res
.innerHTML
= res
.innerHTML
+ "<br>Test " + testNumber
+ ": selectionEnd = " + end
;
45 if (tf
.selectionStart
== expectedStart
&& tf
.selectionEnd
== expectedEnd
)
46 res
.innerHTML
= res
.innerHTML
+ "<br>Passed.<br>";
48 res
.innerHTML
= res
.innerHTML
+ "<br>Failed.<br>";
53 <body onload=
"test()">
54 This tests the selection methods on the new text field.
56 <input type=
"text" id=
"t1" style=
"-khtml-appearance:textfield" value=
"123456789 ABCDEFGHIJ"></input>
57 <div id=
"result"></div>