I am trying to understand to the code example at the top works and the code example at the bottom does not when the only difference is that the code example at the top is using the function name "select" and no matter what the name of the function of the bottom code example is, it does not work. Javascript code example #1 function select() { document.getElementById(first).focus(); document.getElementById(first).select(); } Code (markup): Javascript code example #2 function find() { document.getElementById(first).focus(); document.getElementById(first).select(); } Code (markup): HTML Code <form action='' method='post' name='ex_form'> <textarea rows='5' cols='30' id='first' onClick="select();"> This is some text. </textarea> </form> Code (markup):
first should be enclosed in parenthesis. getElementById expects a string. Also, quick trick: <script type="text/javascript"> function select(text) { text.focus(); text.select(); } </script> <form action='' method='post' name='ex_form'> <textarea rows='5' cols='30' id='first' onClick="select(this)">This is some text.</textarea> </form> Code (markup):