SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

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

    Conditional and anchor jump

    Hi,

    I am using a script called RecoverScroll which returns the page to its last loaded point when reloaded.

    I am using it on a form page, I need it so that...

    1. When the page errors and a div with an ID of #error-box is present in the markup the RecoverScroll script is ignored and the page jumps to #error-box (which isn't in the url)

    2. alternatively, if I could append #error-box to the url if the #error-box div exists in the markup using js I could use the scripts functionality as intended.

    The code to run the script...

    Code:
    <script>
        RecoverScroll.hash();
        RecoverScroll.start('personal-details');
    </script>
    Any help will be appreciated, many thanks.

  2. #2
    SitePoint Addict
    Join Date
    May 2006
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all, has no-one got any ideas on this one?

  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    RecoverScroll might seem slick, but with forms you just need to set focus to a field and the page will scroll to it; maybe write a JS method to "pad" the position so it scrolls to a point above the field, possibly so the field label is visible. Alternatively, if you want to scroll to a particular element, then just find the position and scroll to its top/left offset.

    I know this answer doesn't help with RecoverScroll, but you might do well to reevaluate its usefulness.

  4. #4
    SitePoint Addict
    Join Date
    May 2006
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply Silkster. In this case due to some bad functionality (which I can't change at this point), the page reloads when some form fields are actioned. The page is set up to focus and move to certain fields but it makes it makes for a bad UX as the page is jumping (and scrolling to them is not much better) so I've installed Recoverscroll to remedy this which works great.

    I just need to remove the Recoverscroll functionality IF a div with an ID of #error-box is present in the markup. That or append it to the url in which case I can use Recoverscroll in that instance too. Hope someone can help : )

    If anyone needs anymore information let me know.

  5. #5
    SitePoint Addict
    Join Date
    May 2006
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all, apologies for the bump. Is what I am trying to achieve possible? This is quite urgent now and I will need to look for an alternative if this cannot be achieved.

    Many thanks

  6. #6
    SitePoint Addict
    Join Date
    May 2006
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Morning all,

    Could anyone point me in the right direction with this one?

    In a nutshell, this is what I need.

    -----------------------------

    IF #error-box doesn't exist

    Run recoverscroll (the script from the top message)

    IF #error-box does exist

    Don't run recoverscroll/do nothing

    -----------------------------

    I hope this makes sense.
    Mike


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
  •