select.htm (1294B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title id="desc">HTML5 Selection: Call select() on a text field</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="common.js"></script> 8 <script type="text/javascript"> 9 function RunTest() 10 { 11 var selection = window.getSelection(); 12 var input1 = document.getElementById("input1"); 13 14 assert_equals(input1.selectionStart, 0); 15 assert_equals(input1.selectionEnd, 0); 16 checkDefaultSelectionAttributes(); 17 assert_equals(selection.toString(), ""); 18 19 input1.select(); 20 21 assert_equals(input1.selectionStart, 0); 22 assert_equals(input1.selectionEnd, input1.value.length); 23 checkSelectionAttributes(document.body, 1, document.body, 1, true, 1); 24 assert_equals(selection.toString(), input1.value); 25 } 26 </script> 27 </head> 28 <body onload="test(RunTest);"> 29 <input style="WIDTH: 500px" id="input1" value="Some text in an input control" type="text" /> 30 <p>Select the text in the input element by calling select()</p> 31 </body> 32 </html>