Focus on textfield if url has anchor

Hi all,

I need to focus on a textfield when a page has reloaded and moved to an anchor on the page (and #title is added to the url)

This doesn’t work, am I getting warm?

$(document).ready(function() {
    var pathname = window.location.hash;
	if ($pathname=="#title") {
	    $("#txtFirstname").focus();
	}
});

Many thanks

var pathname = window.location.hash;
		if (pathname=="#title") {
		    $("#txtFirstname").focus(); 
		}

Ah thanks, this works great!

You’re using “$pathname” has the variable in the if statement but it was defined as “pathname”. Once you fix that up it looks like it ought to work.