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
function2
not valid way define function, shouldfunction
- your
settimeout
call wrong because have half cooked function definition there, can passformfocus
first argument - you not calling
timedfocus
anywhere, can call ononload
event
try
function formfocus() { document.getelementbyid('textarea1').focus(); } function timedfocus() { settimeout(formfocus,1000); } window.onload = timedfocus;
demo: fiddle
Comments
Post a Comment