Javascript Function call php Function?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Javascript Function call php Function?

Post by Pyrite »

Is it possible for me to have a JS function that calls a php function inside it. Like I have a JS function that is called with a string, and then that JS could call the php setcookie function with that string?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Ummm not really as javascript is client side and not server side. The way you can get it to work is to have the javascript reload the page with a GET value which causes a function to be run when php parses the page.

Code: Select all

if($_GET[setcookie]){
   //do cookie stuff.
}
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Can php delete/reset cookies that javascript sets?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

i think so becuase after all, they're cookies, i don't think there are different versions :?
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Yea...

Cookies are a product of Netscape, which as we all know, is a product of Uppers :lol:
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

You can get javascript to call PHP functions, and even get data back from PHP functions, without loading the page (or even using iframes).

Add a script tag to your document, give it a URL that loads a blank document. Give that script tag an ID. Now, using javascript, you can modify the src of the script tag, including query string. Because of that, you can pass arguments to a PHP page, which can spit out javascript containing the data. I used this method for a database-fuelled drop-down list (which returns entries from the database that match what you have typed, akin to the windows autocomplete feature, but web-based and fed by DB).
Post Reply