jQuery auto-focus on particular text field after page load

Below code will help us to focus on particular text field in page. It will be used for users to start typing their queries after page is loaded. We can use this in login, search pages etc., for quick access.
jQuery(document).ready(function() {
    var txtField = jQuery("#autocomplete").get(0);
    var elemLen = txtField.value.length;
    txtField.selectionStart = elemLen;
    txtField.selectionEnd = elemLen;
    txtField.focus();
});

Comments

Popular posts from this blog

Send email from xampp localhost

Convert long url to short url using tinyurl api

Modify item price in cart after placing order using sales_quote_add_item