You can not do this directly, what runs on the client has nothing to do with what runs on the server, they are different code bases, they are even different languages. It's like you want to delete an email from your friend, even if you allow it, it would be insecure.
What can be done is to have the client ask the server to do what they want. You have to send a message through the browser and the code on the server will do what it should.
You can do this in a number of ways, one of which is AJAX , which . I already I answered an example for PHP, but in JavaScript it's the same thing .
More on the subject .