Tutorial on Window Onload
<script type="text/javascript"> function my_code(){ alert(" Alert inside my_code function"); var text_val = document.getElementById("t2"); text_val.select(); } window.onload=my_code; </script>