| <html> |
| <head> |
| <script> |
| function test () { |
| var testField = document.getElementById('t1'); |
| var results = document.getElementById('result'); |
| |
| testSelectionRange(1, 0, 0, 0, 0, testField, results); |
| testSelectionEnd(2, 17, 0, 17, testField, results); |
| testSelectionStart(3, 1, 1, 17, testField, results); |
| testSelectionRange(4, 10, 3, 3, 3, testField, results); |
| testSelectionEnd(5, 2, 2, 2, testField, results); |
| testSelectionRange(6, 5, 4, 4, 4, testField, results); |
| testSelectionRange(7, -5, -4, 0, 0, testField, results); |
| testSelectionRange(8, -5, 80, 0, 20, testField, results); |
| testSelectionRange(9, 3, 12, 3, 12, testField, results); |
| |
| } |
| |
| function testSelectionRange (testNumber, start, end, expectedStart, expectedEnd, tf, res) |
| { |
| tf.setSelectionRange(start, end); |
| res.innerHTML = res.innerHTML + "<br>Test " + testNumber + ": setSelectionRange(" + start + ", " + end + ")"; |
| if (tf.selectionStart == expectedStart && tf.selectionEnd == expectedEnd) |
| res.innerHTML = res.innerHTML + "<br>Passed.<br>"; |
| else |
| res.innerHTML = res.innerHTML + "<br>Failed.<br>"; |
| } |
| |
| function testSelectionStart (testNumber, start, expectedStart, expectedEnd, tf, res) |
| { |
| tf.selectionStart = start; |
| res.innerHTML = res.innerHTML + "<br>Test " + testNumber + ": selectionStart = " + start; |
| if (tf.selectionStart == expectedStart && tf.selectionEnd == expectedEnd) |
| res.innerHTML = res.innerHTML + "<br>Passed.<br>"; |
| else |
| res.innerHTML = res.innerHTML + "<br>Failed.<br>"; |
| } |
| |
| function testSelectionEnd (testNumber, end, expectedStart, expectedEnd, tf, res) |
| { |
| tf.selectionEnd = end; |
| res.innerHTML = res.innerHTML + "<br>Test " + testNumber + ": selectionEnd = " + end; |
| if (tf.selectionStart == expectedStart && tf.selectionEnd == expectedEnd) |
| res.innerHTML = res.innerHTML + "<br>Passed.<br>"; |
| else |
| res.innerHTML = res.innerHTML + "<br>Failed.<br>"; |
| } |
| |
| </script> |
| </head> |
| <body onload="test()"> |
| This tests the selection methods on the new text field. |
| <p> |
| <input type="text" id="t1" style="-khtml-appearance:textfield" value="123456789 ABCDEFGHIJ"></input> |
| <div id="result"></div> |
| </p> |
| </body> |
| </html> |