By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,750 Members | 1,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,750 IT Pros & Developers. It's quick & easy.

Javascript execute PHP

P: n/a
Does anyone knows how to execute a PHP function using javascript..
What I want is to do that in the line bellow:
<a href="" target="_blank" onClick="<? add_product_category(); ?>" >add
Category</a>

either by calling a javascript or doing it inline as above.

Thanks !!
Jul 23 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Angelos wrote on 04 jul 2005 in comp.lang.javascript:
Does anyone knows how to execute a PHP function using javascript..
What I want is to do that in the line bellow:
<a href="" target="_blank" onClick="<? add_product_category(); ?>"
add Category</a>


either by calling a javascript or doing it inline as above.


you cannot. serverside code is finished once the client comes into action.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2

P: n/a
Angelos wrote:
Does anyone knows how to execute a PHP function using javascript..
What I want is to do that in the line bellow:
<a href="" target="_blank" onClick="<? add_product_category(); ?>" >add
Category</a>

either by calling a javascript or doing it inline as above.

Thanks !!


Search the group archives at
http://groups.google.com/groups/comp.lang.javascript

Check out FAQ#4.34 at
http://www.jibbering.com/faq/#FAQ4_34

And Jim's intro linked therefrom, to
http://jibbering.com/2002/4/httprequest.html

Jul 23 '05 #3

P: n/a


Well, the client gets what the server serves, the server parses out any
code in the page, when done, it sends the stdout to the client, usually a
page. Now, js can't make a single-function call to php on server over the
wire, it can call a .php with some arguments over the $_GET[] array for
PHP to use them in a function accordingly, but it'll require a page
refresh or a new server transaction for stdout. PHP however, can use ECHO
to output some js code with some values to be used, on the client machine,
That, you can do.
Danny
On Mon, 04 Jul 2005 07:30:31 -0700, Angelos <an*****@redcatmedia.net>
wrote:
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #4

P: n/a
Danny wrote:


Well, the client gets what the server serves, the server parses out
any code in the page, when done, it sends the stdout to the client,
usually a page. Now, js can't make a single-function call to php on
server over the wire, it can call a .php with some arguments over the
$_GET[] array for PHP to use them in a function accordingly, but it'll
require a page refresh or a new server transaction for stdout. PHP
however, can use ECHO to output some js code with some values to be
used, on the client machine, That, you can do.
Danny
On Mon, 04 Jul 2005 07:30:31 -0700, Angelos <an*****@redcatmedia.net>
wrote:


It is not even that difficult if you understand how to do it. And yes, I
can cause javascript to (indirectly) execute a PHP script.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #5

P: n/a


Angelos wrote:
Does anyone knows how to execute a PHP function using javascript..
What I want is to do that in the line bellow:
<a href="" target="_blank" onClick="<? add_product_category(); ?>" >add
Category</a>


You can't do it "inline" like that. PHP scripts run on the server,
JavaScript runs on the browser.

You can link to a page created by a PHP script <a
href="somescript.php">zoop</a>

You can submit a form to a PHP script <form action="somescript.php"...

You can load a PHP page into an iframe.

You can do an xmlHTTPrequest, too.

You have to understand where the code executes!

Jul 23 '05 #6

P: n/a
Thanks aeverybody... the result ... is that I must understand better how and
where the programs are executed !!!
Jul 23 '05 #7

P: n/a


Angelos wrote:
Thanks aeverybody... the result ... is that I must understand better how and
where the programs are executed !!!


Exactly. And it's probably the biggest difference between client-server
progamming and stand-alone programming. Not only when, but where.

A very common approach is to create a PHP 'script' that has more than
one 'incarnation'. Two or three 'pages' from the client's point of
view, but one file on the server.

The PHP file is basically a big 'switch' statement, with the case limb
determined by the presense, or value of a $_POST variable. The first
request from the client will not set the variable, so the default case
is executed, which generates a page with a form.

Next, the user fills out the form and submits it. The same PHP file is
called again, this time seeing posted values, it takes a different
branch of the switch statement, and generates a 'thank you' page or
something.

Back to your original question, how to call PHP from Javascript, you do
it by submitting a form.

Good luck,

Jul 23 '05 #8

P: n/a
Razzbar wrote:

Angelos wrote:
Thanks aeverybody... the result ... is that I must understand better how and
where the programs are executed !!!

<--snip-->
Back to your original question, how to call PHP from Javascript, you do
it by submitting a form.


But that is far from the only way to call a PHP script from Javascript.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #9

P: n/a
Christopher J. Hahn wrote:
Angelos wrote:
Does anyone knows how to execute a PHP function using javascript..
What I want is to do that in the line bellow:
<a href="" target="_blank" onClick="<? add_product_category(); ?>"
>add Category</a>
either by calling a javascript or doing it inline as above.

Thanks !!


Search the group archives at
http://groups.google.com/groups/comp.lang.javascript


Don't use the .com version, use .dk or most other non english speaking
country domain suffix google has.
Check out FAQ#4.34 at
http://www.jibbering.com/faq/#FAQ4_34

And Jim's intro linked therefrom, to
http://jibbering.com/2002/4/httprequest.html



Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jul 23 '05 #10

P: n/a
Stan R. wrote:
Christopher J. Hahn wrote:
Angelos wrote:
Does anyone knows how to execute a PHP function using javascript..
What I want is to do that in the line bellow:
<a href="" target="_blank" onClick="<? add_product_category(); ?>"

add Category</a>

either by calling a javascript or doing it inline as above.

Thanks !!


Search the group archives at
http://groups.google.com/groups/comp.lang.javascript

Don't use the .com version, use .dk or most other non english speaking
country domain suffix google has.


Any particular reason for that asinine suggestion? Executing a PHP
script from javascript is as simple as setting the src of an Image()
object to the PHP script.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #11

P: n/a
Stan R. wrote:
Christopher J. Hahn wrote:
Search the group archives at
http://groups.google.com/groups/comp.lang.javascript


Don't use the .com version, use .dk or most other non english speaking
country domain suffix google has.


Why?
PointedEars
Jul 23 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.