Reputation: 13515
I have the following code inside <table>
tags. item
is the result of the query. When I click on the "(hide)" link display
becomes "false" and the code below is executed. This gets the item that I want to hide from database by id and then changes display property from "True" to "False" and writes it to database. The problem is that since the link refers to the same page (/useradminpage
) after the click, the page returns to the top. If the item is in page 2, and I click "(hide)", it returns to the top of page 1. How do I fix this so that after I click the "(hide)" link it stays on the same place? I was trying to do this with javascript but I could not make it work. Thanks.
...
for item in e:
main_id = item.key().id()
self.response.out.write("""
<tr>
...
<a href="/useradminpage?main_id=%s&display=false">
<span class="small">(hide)</span></a>
...
</td>
</tr>""" % tuple([...main_id...]))
#try to prevent default behavior; but this does not work
self.response.out.write("""<script>
$("a").click(function (evt){
evt.preventDefault();
}</script>""")
self.response.out.write("""</tbody></table>""")
if display == "false":
main_id = self.request.get("main_id")
k = Main.get_by_id(int(main_id))
k.display = False
k.put()
Upvotes: 0
Views: 563
Reputation: 2096
Taking a stab in the dark and guessing you're referring to this?
$("a").click(function (evt){
evt.preventDefault();
}
Stops the page jumping back to the top
Upvotes: 1