Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • trfletch 598 posts 604 karma points
    Jul 14, 2009 @ 11:58
    trfletch
    0

    Doc2form jumping to top of page on submit

    Hi,

    Not sure if there is a solution to this but I have a comments form that sits on the bottom of my page, if the page is quite long then obviously you need to scroll down to get to the comments form. The problem I have is when someone types a comment and clicks submit but they have not entered all the mandatory fields or have not entered a valid email address for example the page jumps back to the top so they would have to scroll back down again to see the error message next to the form. I have tried this with ajax enabled and disabled but it still does the same thing, is there anyway around this so when they click submit it refreshs the page at the same position they were so they can easily see the error message pop-up and make changes to their form?

  • dandrayne 1138 posts 2262 karma points
    Jul 14, 2009 @ 15:01
    dandrayne
    1

    Its a bit cheeky, but sticking

    window.scrollTo = function() { }

    Inside script tags at the top of your page will override the default scrollTo after form submit and your form will go nowhere on submit.  Obviously this will cause any other scrollto functions that you might be using not to work, but who uses them?!

     

     

  • dandrayne 1138 posts 2262 karma points
    Jul 14, 2009 @ 15:01
  • trfletch 598 posts 604 karma points
    Jul 14, 2009 @ 16:05
    trfletch
    0

    Excellent, that now works for when there is a validation error, the next question is can the same thing be done for when someone does submit a valid comment, can the text that is display (i.e. Thank you for your comment) be shown without refreshing the page and jumping back to the top (once again meaning they have to scroll down to the comment section to see the thank you text).

  • dandrayne 1138 posts 2262 karma points
    Jul 14, 2009 @ 16:25
    dandrayne
    1

    If the page properly refreshes then that won't work.  Perhaps you could use a bit of javascript within the thankyou text that forces the page to scroll to it once reloaded

    Thanks text

    <div id="thanksVeryMuch">Thanks for filling in our form, etc etc</div>
    <script type="text/javascript">location.hash="thanksVeryMuch";</script>
  • trfletch 598 posts 604 karma points
    Jul 14, 2009 @ 16:45
    trfletch
    0

    Thanks for the response the only trouble is I do not have a div with the thank you text in, I am just using doc2form and filling in the following macro parameter: TextOnSubmit=

    My other option was going to be to have it redirect to a thank you page but then I would need to have a link to take them back to the page they came from.

  • dandrayne 1138 posts 2262 karma points
    Jul 14, 2009 @ 17:24
    dandrayne
    100

    Try putting the code in the macro parameter (using single quotes).  It's worth a shot ;-)

  • trfletch 598 posts 604 karma points
    Jul 14, 2009 @ 18:01
    trfletch
    0

    Thanks, that seems to work, I suppose the only issue is from an accessibility point of view if javascript is disabled.

  • dandrayne 1138 posts 2262 karma points
    Jul 14, 2009 @ 18:28
    dandrayne
    0

    Call it progressive enhancement if it makes you feel better!  This could be thought of as an enhancement that isn't necessary for the running of the site, everything will still be available to the minority of users that have js disabled, the majority will have the nice touch of less scrolling.

    Dan

  • trfletch 598 posts 604 karma points
    Jul 15, 2009 @ 12:45
    trfletch
    0

    I can live with that, thank you for your help, another problem resolved!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies