Page 1 of 1

Javascript Function call php Function?

Posted: Tue Apr 13, 2004 7:26 am
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?

Posted: Tue Apr 13, 2004 8:07 am
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.
}

Posted: Tue Apr 13, 2004 9:24 am
by Pyrite
Can php delete/reset cookies that javascript sets?

Posted: Wed Apr 14, 2004 5:32 pm
by vigge89
i think so becuase after all, they're cookies, i don't think there are different versions :?

Posted: Wed Apr 14, 2004 5:36 pm
by Pyrite
Yea...

Cookies are a product of Netscape, which as we all know, is a product of Uppers :lol:

Posted: Thu May 13, 2004 11:23 am
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).