How do i activate a click function on a anchor tag?

Im not sure if this has been applied to PHP, but how do i activate a click function on a anchor tag(<a>). I have tried the following but wont work…

<a onclick="someFunction();">CLick me!</a>

<?php
function someFunction(){
alert("I did the function!");
}
?>

onclick events execute javascript code, not serverside code. If you want to achieve something like this, use ajax (jquery + ajax if you like) to make request to a server with javascript

Yes im not saying onclick event neccearly. Im saying something in that range. And i know You cant achieve that using PHP, im asking if somone knows a PHP Framework that can achieve that. @stetim94

Pretty sure there isn’t a framework that can,

The way stetim said is probably the best way using Ajax

REFERENCE:

I have already checked that stackoverflow question @benjnev . And i already know how to do it with Ajax. But im asking for an alternative easy way. Like can larval do it? Or any other PHP Framework? Thankyou

Then if you had read it you would have seen that everyone is saying you can’t do it like that and to use Ajax and jQuery instead. :slight_smile:

It is not php-framework related, i already suggested to use ajax instead. If you combine jquery with ajax it becomes easier, but what exactly are you trying to achieve?

You can use php to fetch data from a database, and then render that to a page, and make a anchor to that page

The reason why i ask you guys…

Oh well… Php has its downfalls…

This is not even php related (depending on what you are trying to achieve), it is just that certain things are client side, other things are server side, both have strong points and weaknesses

This is Php Related… What do you mean. I clearly asked:

So it not php related, php is a server side language. Any server side language would be unable to do this. The link is on client side. So a click function on the link is in the clients browser, thus client side

2 Likes