0

there is any method to prevent page to Stop from jumping to top of page when I click on a link, my link look like that:

 echo "<a href=\"$_SERVER[PHP_SELF]?action=remove&key=$nameskey\">Remove</a>";

This a link where to click when I want to delete a entry from a list ,

I'm using just PHP.

Thanks

Alex
  • 97
  • 1
  • 4
  • 15

2 Answers2

0

You either use ajax or a named anchor in the link that sends the user back down the page when it reloads.

Named anchor: HTML Anchors with 'name' or 'id'?

Ajax method(one of MANY options): http://api.jquery.com/jQuery.ajax/

Community
  • 1
  • 1
Danny
  • 1,185
  • 2
  • 12
  • 33
0

Remove this code immediately. This post gives one reason why. GET requests should never modify anything on the server, especially not deleting.

Instead, you should look into using AJAX. For example:

echo "<a href=\"javascript:remove(this,'".$nameskey."');\">Remove</a>";

And:

<script type="text/javascript">
    function remove(link,key) {
        var a = new XMLHttpRequest();
        a.open("POST","delete.php",true);
        a.onreadystatechange = function() {
            if( this.readyState == 4 && this.status == 200) {
                // assuming the link is a direct child of the element to be removed
                link.parentNode.parentNode.removeChild(link.parentNode);
            }
        };
        a.send("action=remove&key="+key);
    }
</script>
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • The issue isn't with the inherent nature of GET requests, the issue is the lack of security and input/user validation. – Scuzzy Mar 27 '13 at 00:58
  • I'm not deleting anything on the server I just did a list of example some names and when I'm sure my list is complete(remove or adding) I submit my list.Of course my list come from a DB. – Alex Mar 27 '13 at 01:04