javascript - Timed mouse cursor focus? -


i trying focus mouse cursor form text box after webpage loaded using settimeout. did research , found script works.

<script type="text/javascript"> function formfocus() {   document.getelementbyid('element').focus(); } window.onload = formfocus; </script> 

but focuses mouse cursor onload , load few seconds after page loaded. trying use settimeout fire the script above, having difficulties. code below coded. can me out code below , post edited working code of trying accomplish helpful. in advance can lend helping hand, can see still learning.

<script type="text/javascript"> function formfocus() {   document.getelementbyid('textarea1').focus(); } function2 timedfocus() { settimeout(function2()formfocus,1000); } </script> <textarea name="textarea1" id="textarea1" style="position:absolute;left:338px;top:248px;width:150px;height:80px;z-index:0;" rows="2" cols="14"></textarea> 

there syntactical errors in script

  1. function2 not valid way define function, should function
  2. your settimeout call wrong because have half cooked function definition there, can pass formfocus first argument
  3. you not calling timedfocus anywhere, can call on onload event

try

function formfocus() {     document.getelementbyid('textarea1').focus(); } function timedfocus() {     settimeout(formfocus,1000); }  window.onload = timedfocus; 

demo: fiddle


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -