SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

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

    Many thanks

  2. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    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.
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }

  3. #3
    SitePoint Addict
    Join Date
    May 2006
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    var pathname = window.location.hash;
    		if (pathname=="#title") {
    		    $("#txtFirstname").focus(); 
    		}

    Ah thanks, this works great!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •