473,320 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Javascript execute PHP

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
11 17037
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
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


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
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


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
Thanks aeverybody... the result ... is that I must understand better how and
where the programs are executed !!!
Jul 23 '05 #7


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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ronde | last post by:
Hi all, I am in a such situation that requires before Atlas do the Partical/Atlas postback, a Client-Side JavaScript has to be executed first, once the JavaScript execute successfully, the...
4
by: bboyle18 | last post by:
Hi, I am working with a table sorting script which can be found here http://www.workingwith.me.uk/articles/scripting/standardista_table_sorting This script works very nicely, but when there is a...
2
by: Rabel | last post by:
Hi I am a novice with both asp and javascript so I may not even be doing this correctly, but I have an asp page that has variable being passed to it and I have a button that I need to have it go to...
6
by: cantrell78 | last post by:
I can't for the life of me figure out how to execute javascript inside of div that was set using innerHTML or in my case using cloneNode and replaceChild (not my idea to do this, I'm just fixing...
0
by: atencorps | last post by:
Hello I have the following code but need some help on it. The idea of the code is the main sections ie Service Management are viewable when the page is loaded and by clicking on the main...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.