window.onload = function(){ var sample = document.getElementById("test"); sample.value = "damedayo"; } ~~~~ <textarea id = "test"></textarea>
<!DOCTYPE html> <html> <head> <script> function test() { var text = document.getElementById("test").selectionStart; alert(text); } </script> </head> <body> <input type="button" value="押して" onclick="test();"><br> <textarea id="test">テキストエリアです。</textarea> </body> </html>