afridy — 2012-01-30T01:17:47-05:00 — #1
i have a small report generated at the bottom of a page.
it has pagination numbers. all these ajax generated.
now the pagination numbers have the following code.
echo "<a [B]href=[/B]\\"[B]#[/B]\\" id='$i' class='pagenum' onclick='ajaxpost_rep_gen($i);change($i)'/>" . $i . "</a>" . " ";
notice that for hreaf i have put #.
now my problem is, when click a pagination number, the page is scrolled to the top of the page.
so each time when click a pagination number at the bottom, user have to scroll down to see the report's next page.
screen shot of the report :
sdleihssirhc — 2012-01-30T01:31:42-05:00 — #2
I don't have a lot of experience with inline event handlers, but I believe this is an easy fix. Two main solutions:
- Add "return false" to the end of the "onclick" code.
Do either of those help?
paul_wilkins — 2012-01-30T02:04:11-05:00 — #3
Go with the second option, which ensures that when clicking on the link, the browsers default behaviour doesn't not occur.
afridy — 2012-01-30T02:18:17-05:00 — #4
all i can say is ur a genius paul !!!
echo "<a href=\\"#\\" id='$i' class='pagenum' onclick='ajaxpost_rep_gen($i);change($i);return false;'/>" . $i . "</a>" . " ";
both method worked charm. i stick with the above method as per ur advise.
sdleihssirhc — 2012-01-30T02:30:29-05:00 — #5
paul_wilkins — 2012-01-30T02:42:11-05:00 — #6
It's better to use techniques that make it easier to understand what is going on. Returning false from the onclick event serves that purpose nicely.
The other reason to use the return false from the onclick event is that it allows you to cleanly separate the scripting from the content.