473,734 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to call a function when somebody click a link?

i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)

i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link
then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(
now i am thinking using a flag,say,$funct ioncall,
href=$_server[request_url]&functioncal l=1
then if functioncall==1 ,call that function
but is it right?
is there some way simple to do that?
any suggestion is appreciated :)

Nov 4 '06 #1
11 11530

ya******@gmail. com napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)

i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link
then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(
now i am thinking using a flag,say,$funct ioncall,
href=$_server[request_url]&functioncal l=1
then if functioncall==1 ,call that function
but is it right?
is there some way simple to do that?
PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call =helloworld

and in your file script.php such code:

if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}

Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.

Nov 4 '06 #2
the problem is that i donnot want some script.php
i want to redirect the users back on the page they were just on,with
calling a function in advance :)
you think the flag thing is the best way to do it?

Mateusz Markowski wrote:
ya******@gmail. com napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)

i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link
then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(
now i am thinking using a flag,say,$funct ioncall,
href=$_server[request_url]&functioncal l=1
then if functioncall==1 ,call that function
but is it right?
is there some way simple to do that?

PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call =helloworld

and in your file script.php such code:

if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}

Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.
Nov 4 '06 #3
Yes, I think so.

ya******@gmail. com napisal(a):
the problem is that i donnot want some script.php
i want to redirect the users back on the page they were just on,with
calling a function in advance :)
you think the flag thing is the best way to do it?

Mateusz Markowski wrote:
ya******@gmail. com napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)
>
i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link
>
>
then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(
>
>
now i am thinking using a flag,say,$funct ioncall,
href=$_server[request_url]&functioncal l=1
then if functioncall==1 ,call that function
but is it right?
is there some way simple to do that?
>
PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call =helloworld

and in your file script.php such code:

if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}

Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.
Nov 4 '06 #4
but why the second way didnot work out.......
i donot get where did the parse error come from :(
55555555555

Mateusz Markowski wrote:
Yes, I think so.

ya******@gmail. com napisal(a):
the problem is that i donnot want some script.php
i want to redirect the users back on the page they were just on,with
calling a function in advance :)
you think the flag thing is the best way to do it?

Mateusz Markowski wrote:
ya******@gmail. com napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)

i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link


then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(


now i am thinking using a flag,say,$funct ioncall,
href=$_server[request_url]&functioncal l=1
then if functioncall==1 ,call that function
but is it right?
is there some way simple to do that?

>
PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call =helloworld
>
and in your file script.php such code:
>
if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}
>
Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.
Nov 4 '06 #5
Paste the code that you think may give parse error.

ya******@gmail. com napisal(a):
but why the second way didnot work out.......
i donot get where did the parse error come from :(
55555555555

Mateusz Markowski wrote:
Yes, I think so.

ya******@gmail. com napisal(a):
the problem is that i donnot want some script.php
i want to redirect the users back on the page they were just on,with
calling a function in advance :)
you think the flag thing is the best way to do it?
>
Mateusz Markowski wrote:
ya******@gmail. com napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)
>
i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link
>
>
then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(
>
>
now i am thinking using a flag,say,$funct ioncall,
href=$_server[request_url]&functioncal l=1
then if functioncall==1 ,call that function
but is it right?
is there some way simple to do that?
>

PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call =helloworld

and in your file script.php such code:

if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}

Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.
Nov 4 '06 #6
the code is like this
<form action="<?php dec_msgnum($coo kie["usernum"]); echo "<script>";
echo "window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="忽略" /></form>

i also tried
<form action="<?php dec_msgnum($coo kie["usernum"]);
header(default: $_SERVER['PHP_SELF'];';?>"<input type="submit"
value="忽略" /></form>

it didnot work either :(

but this works perfectly well
<form action="<?php dec_msgnum($coo kie["usernum"]); ';?>"<input
type="submit" value="忽略" /></form>

do you think it is caused by some arguements missing?( may be it shoule
be $_SERVER['REQUEST_URI'] or $_SERVER['PHP_SELF']?xxxx=xxxxxx or
something)
Mateusz Markowski wrote:
Paste the code that you think may give parse error.

ya******@gmail. com napisal(a):
but why the second way didnot work out.......
i donot get where did the parse error come from :(
55555555555

Mateusz Markowski wrote:
Yes, I think so.
>
ya******@gmail. com napisal(a):
the problem is that i donnot want some script.php
i want to redirect the users back on the page they were just on,with
calling a function in advance :)
you think the flag thing is the best way to do it?

Mateusz Markowski wrote:
ya******@gmail. com napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)

i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link


then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(


now i am thinking using a flag,say,$funct ioncall,
href=$_server[request_url]&functioncal l=1
then if functioncall==1 ,call that function
but is it right?
is there some way simple to do that?

>
PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call =helloworld
>
and in your file script.php such code:
>
if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}
>
Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.
Nov 4 '06 #7
You should write:
echo "window.locatio n.href={$_SERVE R['PHP_SELF']}";

But it won't work in your browser. Why do you want to put script tags
as action?

ya******@gmail. com napisał(a):
the code is like this
<form action="<?php dec_msgnum($coo kie["usernum"]); echo "<script>";
echo "window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="忽略" /></form>

i also tried
<form action="<?php dec_msgnum($coo kie["usernum"]);
header(default: $_SERVER['PHP_SELF'];';?>"<input type="submit"
value="忽略" /></form>

it didnot work either :(

but this works perfectly well
<form action="<?php dec_msgnum($coo kie["usernum"]); ';?>"<input
type="submit" value="忽略" /></form>

do you think it is caused by some arguements missing?( may be it shoule
be $_SERVER['REQUEST_URI'] or $_SERVER['PHP_SELF']?xxxx=xxxxxx or
something)
Mateusz Markowski wrote:
Paste the code that you think may give parse error.

ya******@gmail. com napisal(a):
but why the second way didnot work out.......
i donot get where did the parse error come from :(
55555555555
>
Mateusz Markowski wrote:
Yes, I think so.

ya******@gmail. com napisal(a):
the problem is that i donnot want some script.php
i want to redirect the users back on the page they were just on,with
calling a function in advance :)
you think the flag thing is the best way to do it?
>
Mateusz Markowski wrote:
ya******@gmail. com napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)
>
i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link
>
>
then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(
>
>
now i am thinking using a flag,say,$funct ioncall,
href=$_server[request_url]&functioncal l=1
then if functioncall==1 ,call that function
but is it right?
is there some way simple to do that?
>

PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Yourlast
example is good way to do it. So you have such link:
script.php?call =helloworld

and in your file script.php such code:

if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}

Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.
Nov 4 '06 #8
so i missed {}
is that the problem?

the browser will recognize it as a javascript and display it only by
the script tag.......
you donot think i shoud put the script tag?

errrrr
why the header() didnot work either?
Mateusz Markowski wrote:
You should write:
echo "window.locatio n.href={$_SERVE R['PHP_SELF']}";

But it won't work in your browser. Why do you want to put script tags
as action?

ya******@gmail. com napisał(a):
the code is like this
<form action="<?php dec_msgnum($coo kie["usernum"]); echo "<script>";
echo "window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="忽略" /></form>

i also tried
<form action="<?php dec_msgnum($coo kie["usernum"]);
header(default: $_SERVER['PHP_SELF'];';?>"<input type="submit"
value="忽略" /></form>

it didnot work either :(

but this works perfectly well
<form action="<?php dec_msgnum($coo kie["usernum"]); ';?>"<input
type="submit" value="忽略" /></form>

do you think it is caused by some arguements missing?( may be it shoule
be $_SERVER['REQUEST_URI'] or $_SERVER['PHP_SELF']?xxxx=xxxxxx or
something)
Mateusz Markowski wrote:
Paste the code that you think may give parse error.
>
ya******@gmail. com napisal(a):
but why the second way didnot work out.......
i donot get where did the parse error come from :(
55555555555

Mateusz Markowski wrote:
Yes, I think so.
>
ya******@gmail. com napisal(a):
the problem is that i donnot want some script.php
i want to redirect the users back on the page they were just on,with
calling a function in advance :)
you think the flag thing is the best way to do it?

Mateusz Markowski wrote:
ya******@gmail. com napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)

i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link


then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(


now i am thinking using a flag,say,$funct ioncall,
href=$_server[request_url]&functioncal l=1
then if functioncall==1 ,call that function
but is it right?
is there some way simple to do that?

>
PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request tothe
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call =helloworld
>
and in your file script.php such code:
>
if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}
>
Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.
Nov 4 '06 #9
no
[Taking a step back]

I think it'd help if the OP says why they want to do all this. If I
ever have trouble doing something I usually find that I am trying to
fit a square peg in a round hole and I need to approach the problem in
a different way.

But, given what we know, it looks like the OP needs one HTML page with
some PHP at the top. Like:

HTML headers
<?php
if (isset($_REQUES T['dofunction'])) {
function();
}
?>
rest of the HTML page including:
<a href="<?php echo $_SERVER['PHP_SELF'].'?dofunction'; ?>">click
here</a>


On 4 Nov 2006 02:45:15 -0800, "Mateusz Markowski"
<ma*****@bsdmai l.orgwrote:
>Paste the code that you think may give parse error.

ya******@gmail .com napisal(a):
>but why the second way didnot work out.......
i donot get where did the parse error come from :(
55555555555

Mateusz Markowski wrote:
Yes, I think so.

ya******@gmail. com napisal(a):
the problem is that i donnot want some script.php
i want to redirect the users back on the page they were just on,with
calling a function in advance :)
you think the flag thing is the best way to do it?

Mateusz Markowski wrote:
ya******@gmail. com napisal(a):
i want to creat a link
when somebody click the link
the php script calls a function,then display itself :)
>
i have tried
<a href=<? funtion(); echo=$_server['php_self'] ?>text</a>
but it will call the function whether i click the link
>
>
then i tried this (using forms)
<form action="<?php function(); echo "<script>"; echo
"window.locatio n.href=$_SERVER['PHP_SELF']"; echo '</script>';?>">
<input type="submit" value="text" /></form>
but it didnot work either.
my browser said there were parse errors,T_STRING expected or
something....:(
>
>
now i am thinking using a flag,say,$funct ioncall,
href=$_server[request_url]&functioncal l=1
then if functioncall==1 ,call that function
but is it right?
is there some way simple to do that?
>

PHP works on a server, not in your browser, so it can't just call
function when you click a link. You have to send a request to the
server which will cause your script to call this function. Your last
example is good way to do it. So you have such link:
script.php?call =helloworld

and in your file script.php such code:

if ($_GET['call'] == 'helloworld') {
echo 'Hello world!';
}

Then after clicking the link your browser sends a request, PHP decides
what to do, then server sends you a appropriate response.
Nov 4 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
56669
by: KS | last post by:
Im trying to prevent the user from clicking any other links on my page when the user have selected/clicked a href once. Sometimes it takes a while before the next page loads so some user will try clicking other links or the same link. I can prevent this when i use buttons by calling onclick and in a javascript getElementsByTagName("input") and then check the type to be type of "button" or "submit" which i then disable. It works. This also...
4
1861
by: ruca | last post by:
Hi, Can anyone tell me how can I call a function of my Web Page from javascritp???? I have a grid that when I click in a cell I want to call another function present in that same page? It is possible to do that?
1
2154
by: Shapper | last post by:
Hello, I have an Asp:LinkButton: <asp:linkbutton id="myLinkButton" runat="server" oncommand="Upload_New_Files"/></asp:linkbutton> I have the following function: Sub Upload_New_Files(ByVal sender As Object, ByVal e As CommandEventArgs) Handles myLinkButton.Click ...
12
5791
by: leaf | last post by:
Hi, How to call function at runtime, based on a struct that contains the information for the function call: struct func_to_call { int function_id; // function id to call unsigned int nparams; // number of parameters unsigned long* parameter; // the parameter(s) to pass }
6
1491
by: Spartanicus | last post by:
I'd like to execute a function when a <link rel="next" href="foo.htm"> type element is used. Although the "onclick" handler is allowed on the element, presumably because the functionality of the element is made available through a browser provided navbar the function doesn't execute when using the element. Anyone know if this is possible? -- Spartanicus
1
4416
by: santosh2003 | last post by:
Hi All, How would we call Javascript function on img click? can we call function which define in codebehind page (.vb page) on img click? Regards Santosh
34
3915
by: majahops via WebmasterKB.com | last post by:
When I click "save" after adding a new record (which contains, among other fields, the person's email address), I want an email to automatically be sent to that person (at the email that is in the field of that record). How can I do this? Thanks so much, it really means so much to me!!! -- Message posted via WebmasterKB.com http://www.webmasterkb.com/Uwe/Forums.aspx/asp/200710/1
0
2309
by: GS | last post by:
IN the application I developing, I have to deal with some https website that uses JavaScript function with parameters in link to open new window when the link is clicked. The default is that the new window will We cannot process your request. Please sign in again. .... How Can I correct this, somehow intercept the click link action and ..?
4
5594
Haitashi
by: Haitashi | last post by:
I have a link and opens up a CFWindow. I'm using the default CFWindow skin. I would like to execute a specific function when the user clicks on the X button. I would like to show a div (which will be hidden by default) when I close the CFWindow. I assume I can use ColdFusion.Window.onHide somehow but I don't know how. All the examples I've seen on the net use a href link to call the onHide handler. I would like to call this event handler...
0
8948
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8780
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9186
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6035
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4816
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3264
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.