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

php

#1

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!");
}
?>

#2

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


#3

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


#4

Pretty sure there isn't a framework that can,

The way stetim said is probably the best way using Ajax

REFERENCE:


#5

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


#6

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. :slightly_smiling:


#7

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


#8

The reason why i ask you guys.....

Oh well... Php has its downfalls....


#9

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


#10

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


#11

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