开发者

How to redirect to the top of a page from a form submit button? HTML/PHP

开发者 https://www.devze.com 2023-01-08 07:41 出处:网络
I have made a personality test u开发者_如何学Csers can fill in. (Its in dutch, find it here: http://www.schoolvoorontwikkeling.nl/contact/nieuwe-test ) It consists of about 15 multiple choice question

I have made a personality test u开发者_如何学Csers can fill in. (Its in dutch, find it here: http://www.schoolvoorontwikkeling.nl/contact/nieuwe-test ) It consists of about 15 multiple choice questions. At the bottom is a submit button, and it is rather far down. When the user clicks it he is redirected to a page that displays his "score" which is basically a rather long description of his personality type, based on the answers.

Now while this is all working swimmingly, what I cannot seem to figure out, is that as soon as the user clicks the submit button and lands on the 'score' (which is a php script that calculates the user score) page, he lands on the same coordinate as the submit button was on the previous page. Which is effectively in the middle of his personality type description.

I would like him to land at the top of the new page, off course, so he can read his description from the beginning, without first having to scroll up. I have tried making the submit button an anchor, but this does not seem to work. Can anyone help me with this?


Try <form action="/whatever/is/in/your-address.something#top">
#top should land on the page top.

Edit: note that with this solution you don't need an anchor with id top.


set an anchor at the top of the results page <a id="pagetop"></a> then on the submitted form action <form action="results.php#pagetop"> might work,

Luke


The results of the test should have different URL than the test, e.g.:

http://www.schoolvoorontwikkeling.nl/contact/nieuwe-test for the test

and

http://www.schoolvoorontwikkeling.nl/contact/nieuwe-test/result for results

And you should use JavaScript and AJAX to see result on the test page without redirection, it'll load the results and it's easy to move to the top of the page using JavaScript.

It's probably not what you expected, but in my opinion, it's the right solution. The test and result are two different pages and should have two different URLs. AJAX and JavaScript will make it display on the same page, if you don't want redirection.

0

精彩评论

暂无评论...
验证码 换一张
取 消