Select text
Shows how to select a text in an textarea
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
<!------>
<script type="text/javascript">
function select_field(id){
document.getElementById(id).focus();
document.getElementById(id).select();
}
function init(){
select_field('text1');
}
onload=init;
</script>
<form>
This field gets selected onload:<br/>
<input type="text" name="text1" id="text1" value="some text" />
<br/>
<textarea name="textarea1" id="textarea1" rows="9" cols="50" wrap="off">Some long
content in here.
abcd efgh abcd efgh abcd efgh
abcd efgh abcd efgh abcd efgh
abcd efgh abcd efgh abcd efgh
</textarea>
<br/>
<input type="button" value="Select text" onclick="select_field('textarea1')">
</form>
X
Url: http://www.jonasjohn.de/snippets/html4strict/select-text.htm
Language: JavaScript | User: ShareMySnippets | Created: Oct 16, 2013