Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set cursor in login form field on page load

I'm trying to get my cursor to load in my login form field on page load. So i'm using this code that supposedly works in every browser but i can't get it to work in any browser lol.

<script type="text/javascript">
$(document).ready(function(){
document.login.input.focus();
});
</script>

Here's the page I'm trying to add it to: http://test.clickacart.com

This should load the cursor in the first username/email field on page load so user doesn't have to click inside to fill it out.

like image 852
sven30 Avatar asked Sep 12 '25 14:09

sven30


1 Answers

Most browsers support the autofocus attribute like this...

<input type='...' autofocus />

The other option is to take the jQuery route like this...

$(function () {
   $('[autofocus]').focus()
});
like image 199
Split Your Infinity Avatar answered Sep 14 '25 05:09

Split Your Infinity



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!